#include<stdio.h>
#define MAX 10
void push( char c, char* s, int* top )
{
if( *top == MAX ) {
printf( "Can not push any more!\n" );
}
else {
s[*top] = c;
(*top)++;
}
}
char pop( char* s, int* top )
{
if( *top == 0 ) {
printf( "No stack!\n" );
return 0;
}
else {
(*top)--;
return s[*top];
}
}
void print_stack_ary( char *s, int top )
{
int i;
for( i = top; i > 0; i-- )
printf( "%c\n", s[i-1] );
}
int main()
{
char s[MAX];
int top = 0;
char c;
push( 'a', s, &top );
push( 'b', s, &top );
push( 'c', s, &top );
push( 'd', s, &top );
push( 'e', s, &top );
print_stack_ary( s, top );
c = pop( s, &top );
printf( "poped %c\n", c );
print_stack_ary( s, top );
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2RlZmluZSBNQVggMTAKCnZvaWQgcHVzaCggY2hhciBjLCBjaGFyKiBzLCBpbnQqIHRvcCApCnsKCWlmKCAqdG9wID09IE1BWCApIHsKCQlwcmludGYoICJDYW4gbm90IHB1c2ggYW55IG1vcmUhXG4iICk7Cgl9CgllbHNlIHsKCQlzWyp0b3BdID0gYzsKCQkoKnRvcCkrKzsKCX0KfQpjaGFyIHBvcCggY2hhciogcywgaW50KiB0b3AgKQp7CglpZiggKnRvcCA9PSAwICkgewoJCXByaW50ZiggIk5vIHN0YWNrIVxuIiApOwoJCXJldHVybiAwOwoJfQoJZWxzZSB7CgkJKCp0b3ApLS07CgkJcmV0dXJuIHNbKnRvcF07Cgl9Cn0Kdm9pZCBwcmludF9zdGFja19hcnkoIGNoYXIgKnMsIGludCB0b3AgKQp7CglpbnQgaTsKCglmb3IoIGkgPSB0b3A7IGkgPiAwOyBpLS0gKQoJCXByaW50ZiggIiVjXG4iLCBzW2ktMV0gKTsKfQppbnQgbWFpbigpCnsKIAoJY2hhciBzW01BWF07CglpbnQgdG9wID0gMDsKCWNoYXIgYzsKCglwdXNoKCAnYScsIHMsICZ0b3AgKTsKCXB1c2goICdiJywgcywgJnRvcCApOwoJcHVzaCggJ2MnLCBzLCAmdG9wICk7CglwdXNoKCAnZCcsIHMsICZ0b3AgKTsKCXB1c2goICdlJywgcywgJnRvcCApOwoKCXByaW50X3N0YWNrX2FyeSggcywgdG9wICk7CgljID0gcG9wKCBzLCAmdG9wICk7CglwcmludGYoICJwb3BlZCAlY1xuIiwgYyApOwoJcHJpbnRfc3RhY2tfYXJ5KCBzLCB0b3AgKTsKICAgIHJldHVybiAwOwp9Cg==