- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 10
- int stack[10];
- int top=-1;
- void push(int number)
- {
- printf("push a number\n");
- if(top>=9)
- {
- printf("the stack is full");
- }else{
- top++;
- stack[top]=number;
- }
- }
- int pop()
- {
- int temp;
- printf("pop a number\n");
- if(top<0)
- {
- printf("the stack is empty");
- return -1;
- }else{
- temp=stack[top];
- top--;
- printf("%d",temp);
- return temp;
- }
- }
- void show()
- {
- for(;top>=0;top--)
- {
- printf("%d\t",stack[top]);
- }
- }
- int main()
- {
- int select;
- int number;
- printf("(1)please input a stack data\n");
- printf("(2)please output a stack data\n");
- printf("(3)exit\n");
- printf("please input one by input a number");
- scanf("%d",&select);
- while(select!=3)
- {
- switch(select)
- {
- case 1:scanf("%d",&number);push(number);break;
- case 2:pop();break;
- default:exit;break;
- }
- printf("(1)please input a stack data\n");
- printf("(2)please output a stack data\n");
- printf("(3)exit");
- printf("please input one by input a number\n");
- scanf("%d",&select);
- }
- show();
- return 0;
- }