- #include <stdio.h>
 - # define SIZE 100
 - void enqueue();
 - void dequeue();
 - void show();
 - int inp_arr[SIZE];
 - int Rear = - 1;
 - int Front = - 1;
 - main()
 - {
 -     int ch;
 -     while (1)
 -     {
 -         printf("1.Enqueue Operation\n");
 -         printf("2.Dequeue Operation\n");
 -         printf("3.Display the Queue\n");
 -         printf("4.Exit\n");
 -         printf("Enter your choice of operations : ");
 -         scanf("%d", &ch);
 -         switch (ch)
 -         {
 -             case 1:
 -             enqueue();
 -             break;
 -             case 2:
 -             dequeue();
 -             break;
 -             case 3:
 -             show();
 -             break;
 -             case 4:
 -             exit(0);
 -             default:
 -             printf("Incorrect choice \n");
 -         } 
 -     } 
 - } 
 -  
 - void enqueue()
 - {
 -     int insert_item;
 -     if (Rear == SIZE - 1)
 -        printf("Overflow \n");
 -     else
 -     {
 -         if (Front == - 1)
 -       
 -         Front = 0;
 -         printf("Element to be inserted in the Queue\n : ");
 -         scanf("%d", &insert_item);
 -         Rear = Rear + 1;
 -         inp_arr[Rear] = insert_item;
 -     }
 - } 
 -  
 - void dequeue()
 - {
 -     if (Front == - 1 || Front > Rear)
 -     {
 -         printf("Underflow \n");
 -         return ;
 -     }
 -     else
 -     {
 -         printf("Element deleted from the Queue: %d\n", inp_arr[Front]);
 -         Front = Front + 1;
 -     }
 - } 
 -  
 - void show()
 - {
 -     
 -     if (Front == - 1)
 -         printf("Empty Queue \n");
 -     else
 -     {
 -         printf("Queue: \n");
 -         for (int i = Front; i <= Rear; i++)
 -             printf("%d ", inp_arr[i]);
 -         printf("\n");
 -     }
 - }
 
  复制代码
  
 
 输出。 
- 1.Enqueue Operation
 - 2.Dequeue Operation
 - 3.Display the Queue
 - 4.Exit
 - Enter your choice of operations : 1
 - Element to be inserted in the Queue: 10
 - 
 - 1.Enqueue Operation
 - 2.Dequeue Operation
 - 3.Display the Queue
 - 4.Exit
 - Enter your choice of operations : 1
 - Element to be inserted in the Queue: 20
 - 
 - 1.Enqueue Operation
 - 2.Dequeue Operation
 - 3.Display the Queue
 - 4.Exit
 - Enter your choice of operations : 3
 - Queue: 
 - 10 20 
 - 
 - 1.Enqueue Operation
 - 2.Dequeue Operation
 - 3.Display the Queue
 - 4.Exit
 - Enter your choice of operations : 2
 - Element deleted from the Queue: 10
 - 
 - 1.Enqueue Operation
 - 2.Dequeue Operation
 - 3.Display the Queue
 - 4.Exit
 - Enter your choice of operations: 3
 - Queue: 
 - 20
 
  复制代码
  |