Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include<iostream>
  2. #define MAX 50
  3.  
  4. using namespace std;
  5.  
  6. class queue
  7. {
  8. int a[MAX];
  9. int rear,front;
  10. public:
  11. queue()
  12. {
  13. rear=0;
  14. front=0;
  15. }
  16. void insert(int x)
  17. {
  18. if(rear==MAX)
  19. {
  20. cout <<"Queue reached Maximum\n";
  21. front=rear=0;
  22. return;
  23. }
  24. a[++rear]=x;
  25. }
  26. void remove()
  27. {
  28. if(front==rear)
  29. {
  30. cout <<"Queue is Empty\n\n";
  31. return;
  32. }
  33. cout <<"deleted\n" <<a[++front]<<" \n";
  34. }
  35. void display()
  36. {
  37. cout << "Queue Size : " << (rear - front);
  38. for(int i=front+1; i<=rear; i++)
  39. cout <<a[i]<<endl;
  40. }
  41.  
  42. };
  43.  
  44. int main()
  45. {
  46. int item;
  47. queue q;
  48. while(1)
  49. {
  50. cout <<"\n1.insert 2.remove 3.display\n\n";
  51. cin >> item;
  52. switch(item)
  53. {
  54. case 1:
  55. cout <<"Enter the elements\n";
  56. for(int i=1; i<=5; i++)
  57. {
  58. cin >> item;
  59. q.insert(item);
  60. }
  61. break;
  62. case 2:
  63. q.remove();
  64. break;
  65. case 3:
  66. q.display();
  67. break;
  68. }
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement