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

Practical No. 9

Uploaded by

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

Practical No. 9

Uploaded by

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

Data Structure Using ‘C’ (22317)

Practical no. 9: Perform Insert and Delete operations on Circular


Queue
Aim: Write a C program to perform insertion and deletion on circular
queue

Program code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define size 5
int cq[size], f = -1, r = -1, i;
void display(){
if(f == -1 && r == -1){
printf("\n Queue is empty...\n");
}
if(f > r){
for(i = f; i <= size-1; i++){
printf("|%d|", cq[i]);
}
for(i = 0; i <= r; i++){
printf("|%d|", cq[i]);
}
}
else{
for(i = f; i <= r; i++){
printf("|%d|", cq[i]);
}
}
}

void insertq(int x){


if((f == 0 && r == size-1) || f == r+1){
printf("\n 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;
}

- Krish Naik (22203B0046)


Data Structure Using ‘C’ (22317)

}
cq[r] = x;
}
}

void deleteq(){
int x;
if(f == -1 && r == -1){
printf("\n Queue underflow...\n");
}
else{
x = cq[f];
printf("\n %d is deleted!", x);
if(f == r){
f = -1;
r = -1;
}
else{
if(f == size-1 && r >= 0){
f = 0;
}
else{
f = f + 1;
}
}
}
}

void main(){
int x, ch;
clrscr();
do{
printf("\n Select any one option:- \n 1. Insert\n 2. Delete\n 3.
Display\n
4. Exit\n Enter your choice: ");
scanf("%d", &ch);
switch(ch){
case 1:
printf("\n Enter the number you want to enter: ");
scanf("%d", &x);
insertq(x);
break;

case 2: deleteq();
break;
case 3: display();
break;
case 4: exit(0);
break;

- Krish Naik (22203B0046)


Data Structure Using ‘C’ (22317)

default:
printf("\n Enter Correct index\n");
break;
}
}while(ch != 4);
getch();
}

- Krish Naik (22203B0046)


Data Structure Using ‘C’ (22317)

Output:

- Krish Naik (22203B0046)


Data Structure Using ‘C’ (22317)

- Krish Naik (22203B0046)

You might also like