Write menu driven program using 'C' for static impletetion of circular queue.The menu includeS -insert -delete -display -exit


#include

#include

#define max 5

int front=-1,rear=0,q[max],ch,temp=-1;

void main()

{

 clrscr();

 while(1)

  {

   printf("\nCircular queue operation");

   printf("\n\n1.To Inseart\n2.To Delete\n3.To Display\n4.To Exit");

   printf("\n\nEnter your choice:");

   scanf("%d",&ch);

   switch(ch)

    {

    case 1:inseart();

               break;

    case 2:delete();

               break;

    case 3:display();

                  break;

    case 4:exit(0);

               break;

    default:printf("\nsorry invalid choice");

     }

  }

}

inseart()

{

 int num;

 if(front==(rear+1)%max)

  {

    printf("\nqueue is full");

    return;

  }

else

  {

    printf("\nEnter the element for the Queue: ");

    scanf("%d",&num);

    if(front==-1)

    front=rear=0;

    else

    rear=(rear+1)%max;

    q[rear]=num;

  }

 return;

}

int delete()

{

  int num;

  if(front==-1)

   {

     printf("\nqueue is empty");

     return;

   }

else

   {

     num=q[front];

     printf("\nElement deleted from Queue is: %d",q[front]);

     if(front==rear)

     front=rear=-1;

     else

     front=(front+1)%max;

   }

 return(num);

}

display()

{

 int i;

 if(front==-1)

  {

   printf("\n\nQueue is empty");

   return;

  }

else

  {

   printf("\nQueue status:");

   for(i=front;i<=rear;i++)

    {

     printf("\n%d",q[i]);

    }

  }

if(front>rear)

  {

   for(i=front;i<max;i++)

    {

     printf("%d\t",q[i]);

    }

     for(i=0;i<=rear;i++)

      {

       printf("%d\t",q[i]);

      }

  }

printf("\n");

}


/*OUTPUT


Circular queue operation


1.To Inseart

2.To Delete

3.To Display

4.To Exit


Enter your choice:1


Enter the element for the Queue: 10



Enter your choice:1


Enter the element for the Queue: 20



Enter your choice:1


Enter the element for the Queue: 30


Circular queue operation


1.To Inseart

2.To Delete

3.To Display

4.To Exit


Enter your choice:3


Queue status:

10

20

30


Circular queue operation


1.To Inseart

2.To Delete

3.To Display

4.To Exit


Enter your choice:2


Element deleted from Queue is: 10


Enter your choice:3


Queue status:

20

30


Circular queue operation


1.To Inseart

2.To Delete

3.To Display

4.To Exit


Enter your choice:4 */
Write menu driven program using 'C' for static impletetion of circular queue.The menu includeS -insert -delete -display -exit Write menu driven program using 'C' for static impletetion of circular queue.The menu includeS -insert -delete -display -exit Reviewed by on November 17, 2013 Rating: 5
Powered by Blogger.