0% found this document useful (0 votes)
24 views4 pages

Practical No 9

The document describes a C program that implements insert and delete operations on a circular queue using an array. The program defines functions to insert elements into the queue, delete elements from the queue, and display all queue elements. It uses global variables to track the front and rear indexes of the queue in the underlying array. The main function provides a menu to call these queue functions and test the circular queue implementation.

Uploaded by

randomgamers613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Practical No 9

The document describes a C program that implements insert and delete operations on a circular queue using an array. The program defines functions to insert elements into the queue, delete elements from the queue, and display all queue elements. It uses global variables to track the front and rear indexes of the queue in the underlying array. The main function provides a menu to call these queue functions and test the circular queue implementation.

Uploaded by

randomgamers613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No-9

Aim: Perform insert and delete operations on circular queue using


array
Perform insert and delete operations on circular queue using array

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define SIZE 5
int cq[SIZE];
int f=-1;
int r=-1;
void insertcq(int x)
{
if ((f==0 && r==SIZE-1)||(f == r+1))
{
printf("Enter QUEUE Overflow\n");
}
else
{
if(f==-1 && r==-1)
{
f= 0;
r= 0;
}
else
{
if(r== SIZE-1 && f!=0)
{
r=0;
}
else
{
r=r+1;
}
}
cq[r]=x;
}
printf("\n");
}

void deletecq()
{
int x;
printf("Deleting element\n");
if(f==-1 && r==-1)
{
printf("QUEUE Underflow\n");
}
else
{
x=cq[f];
printf("%d is deleted\n",x);
if(f==r)
{
f=-1;
r=-1;
}
else
{
if(f==SIZE-1 && r>=0)
{
f=0;
}
else
{
f=f+1;
}
}
}
printf("\n");
}

void displaycq()
{
int i;
printf("QUEUE:\n");
if(f==-1 && r==-1)
{
printf("QUEUE Underflow\n");
}
else
{
if(f>r)
{
for(i=f;i<=SIZE-1;i++)
{
printf("%d\t",cq[i]);
}
for(i=0;i<=r;i++)
{
printf("%d\t",cq[i]);
}
}
else
{
for(i=0;i<=r;i++)
{
printf("%d\t",cq[i]);
}
}
}
printf("\n");
}

int main()
{
int ch,x;
clrscr();
do
{
printf("Queue operatons:\n1.Insert an element\n2.Delete an
element\n3.Display queue elements\n4.Exit\nEnter your choice\n:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter value to be added:\n");
scanf("%d",&x);
insertcq(x);
break;
case 2:
deletecq();
break;
case 3:
displaycq();
break;
case 4:
exit(0);
default:
printf("Enter valid choice\n");
break;
}
}while(ch !=4);

getch();
return 0;
}
OUTPUT:

You might also like