Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
 int queue[SIZE];
 int rear=-1;
 int front=-1;
 void enqueue(int x)
 {
   if(rear==SIZE-1)
     printf("\n queue is full,insertion not possible");
     else
     {
      if(front==-1)
      front=0;
      rear=rear+1;
      queue[rear]=x;
      printf("\n insertion successfull");
     }
 }
 void dequeue()
 {
  if(front==-1||front>rear)
  printf("\n queue is empty,deletion not possible");
  else
  {
   printf("\n deleted element=%d",queue[front]);
   front++;
   if(front>rear)
   front=rear=-1;
  }
}
void display()
{
 int i;
 if(rear==-1)
 printf("\nqueue is empty:");
 else
 {
  printf("\n the element in queue are:");
  for(i=front;i<=rear;i++)
  printf("%d",queue[i]);
 }
}
void main()
{
 int ch,value;
 while(1)
 {
  printf("\n-----------------------------------Menu--------------------------\n");
  printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit");
  printf("\n-------------------------------Enter Choice-------------------------");
  scanf("%d",&ch);
switch(ch)
{
 case 1:
 printf("Value to be inserted is:");
 scanf("%d",&value);
 enqueue(value);
 break;

 case 2:
 dequeue();
 break;

 case 3:
 display();
 break;

 case 4:
 exit(0);
 break;

 default:
 printf("\n Wrong Choice!!");
 }
}
}