Hoon222y

Stack 본문

카테고리 없음

Stack

hoon222y 2018. 10. 21. 23:37
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
#include <iostream>
 
using namespace std;
 
struct st{
    int a[111111];
    int siz;
    st(){
        siz=0;
    }
    int sz() {
        return siz;
    }
    void push(int x){
        a[siz] = x;
        siz++;
    }
    void pop(){
        siz--;
    }
    int top(){
        return a[siz-1];
    }
    bool empty(){
        if(siz==0)return true;
        else return false;
    }
};
 
int main(){
    st stk;
    stk.push(1);
    stk.push(2);
    stk.pop();
    stk.push(3);
    stk.push(4);
    stk.pop();
    printf("%d\n", stk.top());
 
    return 0;
}
 
cs


Comments