CGC_Codes

C# Queue Array

Jan 30th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MAX 50
  4. int queue_array[MAX]
  5. int rear = - 1;
  6. int front = - 1;
  7. main()
  8. {
  9.     int choice;
  10.     while (1)
  11.     {
  12.                 printf("1.Insert element to queue \n");
  13.  
  14.         printf("2.Delete element from queue \n");
  15.  
  16.         printf("3.Display all elements of queue \n");
  17.  
  18.         printf("4.Quit \n");
  19.  
  20.         printf("Enter your choice : ");
  21.  
  22.         scanf("%d", &choice);
  23.  
  24.         switch (choice)
  25.  
  26.         {
  27.             case 1:
  28.             insert();
  29.             break;
  30.             case 2:
  31.             delete();
  32.             break;
  33.             case 3:
  34.             display();
  35.             break;
  36.             case 4:
  37.             exit(1);
  38.             default:
  39.             printf("Wrong choice \n");
  40.         }
  41.     }
  42. }
  43. insert()
  44. {
  45.     int add_item;
  46.     if (rear == MAX - 1)
  47.     printf("Queue Overflow \n")
  48.     else
  49.     {
  50.         if(front == - 1)
  51.         front = 0;
  52.         printf("Inset the element in queue : ");
  53.         scanf("%d" , &add_item);
  54.         rear = rear + 1;
  55.         queue_array[rear] = add_item;
  56.     }
  57. }
  58.  
  59.  
  60. delete()
  61. {
  62.     if(front == - 1 || front > rear)
  63.     {
  64.         printf("Queue Underflow \n");
  65.         return ;
  66.     }
  67.     else
  68.     {
  69.         printf ("Element deleted from queue is : %
  70.         front = front + 1;
  71.     }
  72. }
  73. display()
  74. {
  75.     int i;
  76.     if(front == - 1)
  77.         printf("Queue is empty \n");
  78.     else
  79.     {
  80.         printf("Queue is : \n");
  81.         for (i - front; i <= rear. i++)
  82.             printf("%d", queue_array[i]);
  83.         printf("\n");
  84.     }
  85. }
Add Comment
Please, Sign In to add comment