Turn Desktop View Off
by Dinesh Thakur

 

#include<stdio.h>

#include<process.h>
#define SIZE 5
int rear=-1;
int front=-1;
int a[SIZE];
void main()
{
        void insert(int);
        int del();
        void display();
        int i,j,k;
        char ch;
        do
         {
                      clrscr();
                      printf("\n1.PUSH");
                      printf("\n2.POP");
                      printf("\n3.DISPLAY");
                      printf("\n4.EXIT");
                      printf("\nENTER YOUR CHOICE");
                      scanf("%d",&i);
                      switch(i)
                         {
                            case 1:           printf("enter the item to be pushed");
                                                 scanf("%d",&j);
                                                 insert(j);
                                                 display();
                                                 break;
                            case 2:           j=del();
                                                 printf("the item deleted is %d\n",j);
                                                 display();
                                                 break;
                            case 3:           display();
                                                 break;
                            case 4:           exit(0);
                                                 break;
                                                 default:printf("\n any choice");
                         }
                                                 fflush(stdin);
                                                 printf("want to perform any more");
                                                 scanf("%c",&ch);
           }while(ch=='y');
}
     void insert(int item)
            {
                 rear++;
                 if(rear==0)
                    {
                           front=0;
                    }
                 else if(rear==SIZE)
                         {
                                 printf("queue full");
                                 rear--;
                                 return;
                          }
                                 a[rear]=item;
                                 return;
              }
      int del()
             {
                   int item ;
                   if(front==-1)
                     {
                           printf("queue under flow");
                           return 0;
                     }
                   else if(rear==front)
                          {
                                 item=a[front];
                                 front=-1;
                           }
                         else
                          {
                                 item =a[front];
                           }
                                 return item;
              }
                 void display()
             {
                   int i;
                   for(i=front;i<=rear;i++)
                       {
                            printf("%d--",a[i]);
                       }
                            return;
             }