Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define size 6
  6. int r = 0;
  7. int f = 0;
  8. char queue[size];
  9.  
  10. void enQueue(char X)
  11. {
  12. if (r > size)
  13. {
  14. cout << "OVERFLOW!!" << endl;
  15. return;
  16. }
  17. else {
  18. queue[r++] = X;
  19.  
  20. }
  21. }
  22. char deQueue()
  23. {
  24. if (f == r)
  25. {
  26. cout << "UNDERFLOW!!" << endl;
  27.  
  28. }
  29. else{
  30.  
  31. return queue[f++] ;
  32. }
  33. }
  34.  
  35. void display()
  36. {
  37. if (f <= r) /// (if (F < R))
  38. {
  39. cout << "QUEUE INTRUMENT'S ARE: " << endl;
  40. //return;
  41. for (int i = f; i <= r; i++)
  42. {
  43. cout << queue[i] << " ";
  44. cout << endl;
  45. }
  46. }
  47. else
  48. {
  49. cout << "EMPTY!!" << endl;
  50. }
  51.  
  52. }
  53.  
  54. int main()
  55. {
  56. int key;
  57. while (true)
  58. {
  59. cout << "1.INSERT 2.DELETE 3.SHOW 4.EXITS" << endl;
  60. cin >> key;
  61.  
  62. switch (key)
  63. {
  64. case 1:
  65. char ele;
  66. cout << "INSERT ALL: ";
  67. cin >> ele;
  68. enQueue(ele);
  69. break;
  70.  
  71. case 2:
  72. cout << "DELETED ALL: " << deQueue() << endl ;
  73. break;
  74. case 3:
  75. display();
  76. cout << endl;
  77. break;
  78. case 4:
  79. return 0;
  80.  
  81. break;
  82. }
  83. }
  84.  
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement