#include <iostream>
using namespace std;

void push(int *s, int &top, int n){
if(top!=9){
top++;
s[top]=n;
}
}

void pop(int *s, int &top){
if(top!=-1){
top--;
}
}

void print_stack(int *s, int top){
while(top>-1){
cout<<s[top]<<endl;
top--;
}
}

int main(){
int s[10];
int top=-1;

push(s,top,1);
push(s,top,2);
push(s,top,3);
push(s,top,4);
push(s,top,5);

print_stack(s,top);

cout<<"pop도 해보자"<<endl;

pop(s,top);
pop(s,top);

print_stack(s,top);

cout<<"다시 push를 해보자"<<endl;

push(s,top,6);
push(s,top,7);

print_stack(s,top);

cout<<"아주 잘 되는구나 ^^v"<<endl;

return 0;
}

Posted by 공돌이pooh
,