Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- #define Max 3
- void Push(void);
- void Pop(void);
- void List(void);
- int top = -1;
- char array[Max][20];
- int main()
- {
- while(1)
- {
- char option;
- printf(" Stack\n");
- printf("-------------------\n");
- printf("<1> Push\n");
- printf("<2> Pop\n");
- printf("<3> List\n");
- printf("<4> Quit\n");
- printf("-------------------\n");
- printf("Please enter your choice:");
- option = getch();
- switch(option)
- {
- case '1':
- Push();
- break;
- case '2':
- Pop();
- break;
- case '3':
- List();
- break;
- case '4':
- exit(0);
- default:
- printf("Input error!\n");
- }
- }
- return 0;
- }
- void Push(void)
- {
- if(top >= Max - 1)
- printf("Full\n");
- else
- {
- top++;
- printf("\n\nPlease enter an item:");
- gets(array[top]);
- }
- }
- void Pop(void)
- {
- if(top<0)
- printf("No item to stack,it's empty!\n");
- else
- {
- printf("Pop this item: %s\n",array[top]);
- top--;
- }
- }
- void List(void)
- {
- int count = 0;
- if(top<0)
- printf("No item to stack,it's empty!\n");
- else
- {
- int i,count = 0;
- printf("stack list:\n");
- for(i = top;i >= 0;i--)
- {
- printf("%s\n",array[i]);
- count++;
- if(count % 20 ==0)
- getch();
- }
- printf("Total item is:%d\n",count);
- }
- }
Add Comment
Please, Sign In to add comment