Advertisement
lordasif

queue

Mar 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int queue[100], n = 100, front = - 1, rear = - 1;
  4. void Insert() {
  5. int val;
  6. if (rear == n - 1)
  7. cout<<"Queue Overflow"<<endl;
  8. else {
  9. if (front == - 1)
  10. front = 0;
  11. cout<<"Insert the element in queue : "<<endl;
  12. cin>>val;
  13. rear++;
  14. queue[rear] = val;
  15. }
  16. }
  17. void Delete() {
  18. if (front == - 1 || front > rear) {
  19. cout<<"Queue Underflow ";
  20. return ;
  21. } else {
  22. cout<<"Element deleted from queue is : "<< queue[front] <<endl;
  23. front++;;
  24. }
  25. }
  26. void Display() {
  27. if (front == - 1)
  28. cout<<"Queue is empty"<<endl;
  29. else {
  30. cout<<"Queue elements are : ";
  31. for (int i = front; i <= rear; i++)
  32. cout<<queue[i]<<" ";
  33. cout<<endl;
  34. }
  35. }
  36. int main() {
  37. int ch;
  38. cout<<"1) Insert element to queue"<<endl;
  39. cout<<"2) Delete element from queue"<<endl;
  40. cout<<"3) Display all the elements of queue"<<endl;
  41. cout<<"4) Exit"<<endl;
  42. do {
  43. cout<<"Enter your choice : "<<endl;
  44. cin<<ch;
  45. switch (ch) {
  46. case 1: Insert();
  47. break;
  48. case 2: Delete();
  49. break;
  50. case 3: Display();
  51. break;
  52. case 4: cout<<"Exit"<<endl;
  53. break;
  54. default: cout<<"Invalid choice"<<endl;
  55. }
  56. } while(ch!=4);
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement