Circular Queue Using Array
Circular Queue Using Array
#include<stdio.h>
#define SIZE 5
void insert();
void delet();
void display();
main()
{
int ch;
do
{
printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
delet();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("\n\nInvalid choice. Pleasr try again...\n");
}
} while(1);
getch();
}
www.eazynotes.com Gursharan Singh Tatla Page No. 2
void insert()
{
if((front==0 && rear==SIZE-1) || (front==rear+1))
printf("\n\nQueue is full.");
else
{
printf("\n\nEnter ITEM: ");
scanf("%d", &item);
if(rear == -1)
{
rear = 0;
front = 0;
}
else if(rear == SIZE-1)
rear = 0;
else
rear++;
queue[rear] = item;
printf("\n\nItem inserted: %d\n", item);
}
}
void delet()
{
if(front == -1)
printf("\n\nQueue is empty.\n");
else
{
item = queue[front];
if(front == rear)
{
front = -1;
rear = -1;
}
else if(front == SIZE-1)
front = 0;
else
front++;
void display()
{
int i;