Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. string stack[100], queue[100];
  6. int i,m=100,n=100,top=-1,countNum=0,countQue=0,bottom=-1,down=-1;
  7. /////STACK AREA
  8. void push(string val)
  9. {
  10. if(top>=n-1){
  11. cout<<"Stack overflow"<<endl;
  12. }
  13. else
  14. {
  15. top++;
  16. stack[top]=val;
  17. }
  18. }
  19.  
  20. void pop()
  21. {
  22. if(top<=-1){
  23. cout<<"Stack undeflow"<<endl;
  24. }
  25. else
  26. {
  27. cout<<"The popped element is: "<<stack[top]<<endl;
  28. top--;
  29. }
  30. }
  31.  
  32. void display()
  33. {
  34. if(top>=0){
  35. cout<<"The stack name is: "<<stack[top]<<endl;
  36. }
  37. else
  38. {
  39. cout<<"Stack is empty"<<endl;
  40. }
  41. }
  42. void count()
  43. {
  44. cout<<"\nSize of stack is: "<<countNum<<endl;
  45. }
  46.  
  47. /////QUEUE AREA
  48. void posh()
  49. {
  50. string inp;
  51. if (bottom==m-1)
  52. {
  53. cout<<"Queue overflow"<<endl;
  54. }
  55. else
  56. {
  57. bottom++;
  58. queue[bottom] = inp;
  59. }
  60. }
  61.  
  62. void del()
  63. {
  64. if (bottom==-1)
  65. {
  66. cout<<"Queue undeflow"<<endl;
  67. }
  68. else
  69. {
  70. cout<<"The popped element is: "<<queue[bottom]<<endl;
  71. bottom++;
  72. }
  73. }
  74.  
  75. void disc()
  76. {
  77. if (down>=-1)
  78. {
  79. cout<<"Queue is empty"<<endl;
  80. }
  81. else
  82. {
  83. for(i=down;i <= bottom; i++)
  84. cout<<"The queue is: "<<queue[i]<<endl;
  85. }
  86. }
  87. void countt()
  88. {
  89. cout<<"The queue size is: "<<countQue<<endl;
  90. }
  91.  
  92. int main()
  93. {
  94. int s,t;
  95. string val,inp;
  96. cout<<"(1) STACK"<<endl;
  97. cout<<"(2) QUEUE"<<endl;
  98. cout<<endl;
  99. cout<<"Enter your choice: ";
  100. cin>>t;
  101.  
  102. switch(t){
  103. case 1:
  104. {
  105. do{
  106. //stack
  107. cout<<"(1) PUSH"<<endl;
  108. cout<<"(2) POP"<<endl;
  109. cout<<"(3) DISPLAY"<<endl;
  110. cout<<"(4) SHOW"<<endl;
  111. cout<<"(5) EXIT"<<endl;
  112. cout<<endl;
  113. cout<<"Enter your choice: ";
  114. cin>>s;
  115.  
  116. switch(s)
  117. {
  118. case 1:
  119. {
  120. cout<<"Enter name: ";
  121. cin>>val;
  122. push(val);
  123. countNum++;
  124. break;
  125. }
  126. case 2:
  127. {
  128. pop();
  129. countNum--;
  130. break;
  131. }
  132. case 3:
  133. {
  134. display();
  135. break;
  136. }
  137. case 4:
  138. {
  139. count();
  140. break;
  141. }
  142. case 5:
  143. {
  144. exit(0);
  145. }
  146. }
  147. }while(s!=5);
  148. }
  149.  
  150. case 2:
  151. {
  152. do{
  153. ////QUEUE
  154. cout<<"(1) PUSH"<<endl;
  155. cout<<"(2) POP"<<endl;
  156. cout<<"(3) DISPLAY"<<endl;
  157. cout<<"(4) SHOW"<<endl;
  158. cout<<"(5) EXIT"<<endl;
  159. cout<<endl;
  160. cout<<"Enter your choice: ";
  161. cin>>s;
  162.  
  163. switch(s)
  164. {
  165. case 1:
  166. {
  167. cout<<"Enter name: ";
  168. cin>>val;
  169. posh();
  170. countQue++;
  171. break;
  172. }
  173. case 2:
  174. {
  175. del();
  176. countQue--;
  177. break;
  178. }
  179. case 3:
  180. {
  181. disc();
  182. break;
  183. }
  184. case 4:
  185. {
  186. countt();
  187. break;
  188. }
  189. case 5:
  190. {
  191. break;
  192. }
  193. }
  194. }while(s!=5);
  195. }
  196. }
  197.  
  198.  
  199. return 0;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement