Circular Queues on Array using DevC++
#include <conio.h>
#include <stdlib.h>
#define n 6
int array [n];
int front=0;
int rear=0;
int pick;
void insertion ()
{
if((rear+1)%n==front)
{
printf ("Queue is Full");
}
else
{
rear=(rear+1)%n;
printf ("Input value = ");
scanf ("%d",&array[rear]);
}
}
void deletion ()
{
if (front==rear)
{
printf ("Queues is empty");
}
else
{
printf ("Elemen to be deleted = %d", array[front+1]);
front=(front+1)%n;
}
}
void display ()
{
if (front==rear)
{
printf ("Queues is empty");
}
else
{
printf ("Elemen of Queues = \n");
for (int i=front+1;i<=rear;i=(i+1)%n)
{
printf ("%d\n", array[i]);
}
}
}
int main ()
{
do
{
printf ("\n\nQueues Using Circular Array");
printf ("\n1. Insert Queues");
printf ("\n2. Deletion Queues");
printf ("\n3. Display Queues");
printf ("\nInsert your selection = ");
scanf ("%d",&pick);
switch (pick)
{
case 1:
insertion ();
break;
case 2:
deletion ();
break;
case 3:
display ();
break;
}
}while (pick!=0);
getche ();
return 0;
}