Data Structure Queue

  1. #include < stdio.h > int rear = 0;  
  2. int front = 0;  
  3. int max = 25;  
  4. int queue[100];  
  5. main()  
  6. {  
  7.     int ch;  
  8.     void insert();  
  9.     void delete();  
  10.     void isempty();  
  11.     void isfull();  
  12.     void showqueue();  
  13.     void compact();  
  14.     do {  
  15.             int data;  
  16.         printf("\t*******QUEUE ARRAY********");  
  17.         printf("\t==========================\n");  
  18.         printf("\t 1:insert\n");  
  19.         printf("\t 2:delete\n");  
  20.         printf("\t 3:isempty\n");  
  21.         printf("\t 4:isfull\n");  
  22.         printf("\t 5:show queue\n");  
  23.         printf("\t 7:stop\n");  
  24.         printf("\t===========================\n");  
  25.         printf("enter your choice\n");  
  26.         scanf("%d", & ch);  
  27.         switch (ch)  
  28.         {  
  29.             case 1: // call insert function and BREAK after that  
  30.             {  
  31.                 insert();  
  32.                 break;  
  33.             }  
  34.             case 2: // call delete function and BREAK after that  
  35.             {  
  36.                 delete();  
  37.                 break;  
  38.             }  
  39.             case 3: // call isempty function and BREAK after that  
  40.             {  
  41.                 isempty();  
  42.                 break;  
  43.             }  
  44.             case 4: // call isfull function and BREAK after that  
  45.             {  
  46.                 isfull();  
  47.                 break;  
  48.             }  
  49.             case 5: // call show function and BREAK after that  
  50.             {  
  51.                 showqueue();  
  52.                 break;  
  53.             }  
  54.             case 6:  
  55.             {  
  56.                 printf("program ended\n");  
  57.                 break;  
  58.             }  
  59.             default:  
  60.             {  
  61.                 printf("enter valid choice");  
  62.                 break;  
  63.             }  
  64.             }  
  65.         }  
  66.         // end of do while  
  67.         while (ch != 6);  
  68.     }  
  69.     //-------------------------------------------------------------//  
  70.     void insert() //function to insert  
  71.     {  
  72.         int data;  
  73.         if (rear == max)  
  74.         {  
  75.             printf("queue is full\n");  
  76.         }  
  77.         else  
  78.         {  
  79.             rear = rear + 1;  
  80.             printf("enter the data\n");  
  81.             scanf("%d", & data);  
  82.             queue[rear] = data;  
  83.             printf("\t inserted data\n");  
  84.         }  
  85.     }  
  86.     //-----------------------------------------------------------//  
  87.     void delete() //function to delete  
  88.     {  
  89.         if (rear == front)  
  90.         {  
  91.             printf("\nstack is empty");  
  92.         }  
  93.         else  
  94.         {  
  95.             front = front + 1;  
  96.             printf("%d", queue[front]);  
  97.             printf("\n delete data");  
  98.         }  
  99.     }  
  100.     //----------------------------------------------------------//  
  101.     void isempty() //function to isempty  
  102.     {  
  103.         if (rear == front)  
  104.         {  
  105.             printf("queue is empty");  
  106.         }  
  107.         else  
  108.         {  
  109.             printf("queue is not empty");  
  110.         }  
  111.     }  
  112.     //----------------------------------------------------------//  
  113.     void isfull() //function to isfull  
  114.     {  
  115.         if (rear == front)  
  116.         {  
  117.             printf("queue is full");  
  118.         }  
  119.         else  
  120.         {  
  121.             printf("queue is not full");  
  122.         }  
  123.     }  
  124.     //-----------------------------------------------------------//  
  125.     void showqueue() //function to top of stack  
  126.     {  
  127.         int i;  
  128.         for (i = front + 1; i < rear; ++i)  
  129.         {  
  130.             printf("data top of stack=%d\n", queue[i]);  
  131.         }  
  132.     }