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

Ds Practical 4

This document contains a C program that implements a circular queue with basic operations such as insertion, deletion, and display. The user can interact with the queue through a menu-driven interface. The program handles cases for a full or empty queue and allows for continuous operation until the user chooses to exit.

Uploaded by

aniketchate50
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)
3 views4 pages

Ds Practical 4

This document contains a C program that implements a circular queue with basic operations such as insertion, deletion, and display. The user can interact with the queue through a menu-driven interface. The program handles cases for a full or empty queue and allows for continuous operation until the user chooses to exit.

Uploaded by

aniketchate50
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/ 4

#include<stdio.

h>
#include<stdlib.h>
#define MAXSIZE 5
int cq[MAXSIZE];
int front = -1,rear = 0;
void cqinsert();
int cqdelete();
void display();
void main ()
{
int choice;
do
{
printf("\n1.insert");
printf("\n2.Delete");
printf("\n3.Display");
printf("\n4.Exit");
printf("\n______________________________________________");
printf("\n Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
cqinsert();
break;
case 2:
cqdelete();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\n invalid choice.Please try again");
}
} while(choice != 4);
}
void cqinsert(){
int num;
if (front == (rear + 1) % MAXSIZE)
{
printf("\n Queue is full");
return ;
}
else{
printf("\n Enter the element to be insert: ");
scanf("%d",&num);
if (front== -1)
front = rear = 0;
else
rear = (rear + 1)% MAXSIZE;
cq[rear]= num;
}
}
int cqdelete(){
int num;
if ( front == -1)
{
printf("\n Queue in empty");
return -1;
}
else{
num = cq[front];
printf("\n Delete element is = %d", cq[front]);
if ( front == rear)
front = rear = -1;
else
front = (front + 1 ) % MAXSIZE;
}
return num;
}
void display(){
int i;
if (front == -1)
{
printf("\n Queue is empty");
return ;
}
else{
printf("\nElement of the queue: ");
for (i = front; i <= rear; i++)
{
printf("%d",cq[i]);
}
}
if ( front > rear){
for ( i = front; i < MAXSIZE; i++)
{
printf("%d",cq[i]);
}
for (i = 0; i <=rear; i++)
{
printf("%d", cq[i]);
}
}
printf("\n");
}

Output:
1.insert
2.Delete
3.Display
4.Exit
______________________________________________
Enter your choice: 1
Enter the element to be insert: 5
1.insert
2.Delete
3.Display
4.Exit
______________________________________________
Enter your choice: 3
Element of the queue: 5
1.insert
2.Delete
3.Display
4.Exit
______________________________________________
Enter your choice:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy