Guest User

Untitled

a guest
Nov 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #define Max 3
  6. void Push(void);
  7. void Pop(void);
  8. void List(void);
  9. int top = -1;
  10. char array[Max][20];
  11. int main()
  12. {
  13. while(1)
  14. {
  15. char option;
  16. printf(" Stack\n");
  17. printf("-------------------\n");
  18. printf("<1> Push\n");
  19. printf("<2> Pop\n");
  20. printf("<3> List\n");
  21. printf("<4> Quit\n");
  22. printf("-------------------\n");
  23. printf("Please enter your choice:");
  24. option = getch();
  25. switch(option)
  26. {
  27. case '1':
  28. Push();
  29. break;
  30. case '2':
  31. Pop();
  32. break;
  33. case '3':
  34. List();
  35. break;
  36. case '4':
  37. exit(0);
  38. default:
  39. printf("Input error!\n");
  40. }
  41. }
  42. return 0;
  43. }
  44.  
  45. void Push(void)
  46. {
  47. if(top >= Max - 1)
  48. printf("Full\n");
  49. else
  50. {
  51. top++;
  52. printf("\n\nPlease enter an item:");
  53. gets(array[top]);
  54. }
  55. }
  56. void Pop(void)
  57. {
  58. if(top<0)
  59. printf("No item to stack,it's empty!\n");
  60. else
  61. {
  62. printf("Pop this item: %s\n",array[top]);
  63. top--;
  64. }
  65. }
  66. void List(void)
  67. {
  68. int count = 0;
  69. if(top<0)
  70. printf("No item to stack,it's empty!\n");
  71. else
  72. {
  73. int i,count = 0;
  74. printf("stack list:\n");
  75. for(i = top;i >= 0;i--)
  76. {
  77. printf("%s\n",array[i]);
  78. count++;
  79. if(count % 20 ==0)
  80. getch();
  81. }
  82. printf("Total item is:%d\n",count);
  83. }
  84. }
Add Comment
Please, Sign In to add comment