SHARE
TWEET

Untitled

a guest Jan 28th, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int const capctiy = 100;
  4. int queue[capctiy], front = -1, rear = -1;
  5.  
  6. void Insert() {
  7.     int val;
  8.     if (rear == capctiy - 1)
  9.         cout << "Queue is Full" << endl;
  10.     else {
  11.         if (front == -1)
  12.             front = 0;
  13.         cout << "Insert the element in queue : " << endl;
  14.         cin >> val;
  15.         rear++;
  16.         queue[rear] = val;
  17.     }
  18. }
  19. void Delete() {
  20.     if (front == -1 || front > rear) {
  21.         cout << "Queue Underflow ";
  22.         return;
  23.     }
  24.     else {
  25.         cout << "Element deleted from queue is : " << queue[front] << endl;
  26.         front++;;
  27.     }
  28. }
  29. void Display() {
  30.     if (front == -1)
  31.         cout << "Queue is empty" << endl;
  32.     else {
  33.         cout << "Queue elements are : ";
  34.         for (int i = front; i <= rear; i++)
  35.             cout << queue[i] << " ";
  36.         cout << endl;
  37.     }
  38. }
  39. int main() {
  40.     int ch;
  41.     cout << "1) Insert element to queue" << endl;
  42.     cout << "2) Delete element from queue" << endl;
  43.     cout << "3) Display all the elements of queue" << endl;
  44.     cout << "4) Exit" << endl;
  45.     do {
  46.         cout << "Enter your choice : " << endl;
  47.         cin >> ch;
  48.         switch (ch) {
  49.         case 1: Insert();
  50.             break;
  51.         case 2: Delete();
  52.             break;
  53.         case 3: Display();
  54.             break;
  55.         case 4: cout << "Exit" << endl;
  56.             break;
  57.         default: cout << "Invalid choice" << endl;
  58.         }
  59.     } while (ch != 4);
  60.     return 0;
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top