Queue Insert Delete Display Exit

#include<stdio.h>
#include<conio.h>
#define boundary 5
struct queue
{
	int item[boundary];
   int front,rear;
};
struct queue q;
void insertion();
void display();
void delet();
int main ()
{
   int ch=0;
	q.front=0;
   q.rear=-1;

   clrscr();
   while(ch!=4)
   {
   	printf("\n1. Insertion\n2. Deletion\n3. Display\n4. Exit\n\n");
   	scanf("%d",&ch);
   	switch(ch)
   	{
   		case 1: insertion();
      	break;
         case 2: delet();
      	break;
      	case 3: display();
      	break;
         default : printf("\nPlease enter the right choise!\n");
   	}
   }
}
void insertion()
{
   int e;
	if(q.rear+1==boundary)
   	printf("No space!\n");
   else
   {
      printf("Enter the element: ");
      scanf("%d",&e);
   	q.rear++;
      q.item[q.rear]=e;
   }
}
void display()
{
	int i;
	if(q.rear<q.front)
   	printf("No data in queue!\n");
   else
   {
      printf("\nThe elements are: ");
   	for(i=q.front;i<=q.rear;i++)
      	printf("%d ",q.item[i]);
      printf("\n");
      if(boundary==i)
   		printf("Queue is full!\n");
   }
}
void delet()
{

	if(q.rear+1==q.front)
   	printf("No data in queue!\n");
   else
   	q.front++;
}

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *