본문 바로가기
Computer Science

stack

by OKOK 2019. 1. 17.

1. 이렇게 복사하고

2. 저렇게 복사하고

3. 오케이

4. 어떻게 쓰는지 알았음

5. 주소값을 넣고

6. 그 안에서 메모리 주소 값을 두고 변하게 만듦 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
 
#define MAX_N 100
 
int top;
int stack[MAX_N];
 
void stackInit(void)
{
    top = 0;
}
 
int stackIsEmpty(void)
{
    return (top == 0);
}
 
int stackIsFull(void)
{
    return (top == MAX_N);
}
 
int stackPush(int value)
{
    if (stackIsFull())
    {
        printf("stack overflow!");
        return 0;
    }
    stack[top] = value;
    top++;
 
    return 1;
}
 
int stackPop(int *value)
{
    if (top == 0)
    {
        printf("stack is empty!");
        return 0;
    }
    top--;
    *value = stack[top];
 
    return 1;
}
 
int main(int argc, char* argv[])
{
    freopen("input.txt""r", stdin);
    int T, N;
 
    scanf("%d"&T);
 
    for (int test_case = 1; test_case <= T; test_case++)
    {
        scanf("%d"&N);
        stackInit();
        for (int i = 0; i < N; i++)
        {
            int value;
            scanf("%d"&value);
            stackPush(value);
        }
 
        printf("#%d ", test_case);
 
        while (!stackIsEmpty())
        {
            int value;
            if (stackPop(&value) == 1)
            {
                printf("%d ", value);
            }
        }
        printf("\n");
    }
    return 0;
}
cs

 


'Computer Science' 카테고리의 다른 글

2019112 우선순위 큐, 힙, 링크드 리스트  (0) 2019.01.17
queue  (0) 2019.01.17
Tree PreOrder  (0) 2019.01.16
Graph  (0) 2019.01.16
Linked List  (0) 2019.01.16

댓글