0% found this document useful (0 votes)
2 views

queue

The document contains a C++ program that implements a queue data structure with basic operations such as insertion, deletion, and display. It allows the user to interactively manage the queue through a menu-driven interface. The program handles overflow and underflow conditions appropriately.

Uploaded by

22uit048
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)
2 views

queue

The document contains a C++ program that implements a queue data structure with basic operations such as insertion, deletion, and display. It allows the user to interactively manage the queue through a menu-driven interface. The program handles overflow and underflow conditions appropriately.

Uploaded by

22uit048
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

#include<iostream.

h>

#include<conio.h>

#include<stdlib.h>

void insert();

void deletion();

void display();

int front=-1,rear=-1;

int queue[20],n;

void main()

clrscr();

int choice;

cout<<"\n Enter the number of elements to be inserted:";

cin>>n;

while(1)

cout<<"\n 1.insert an element \n 2.delete an element \n 3.display the queue \n 4.Exit";

cout<<"\n Enter your choice:";

cin>>choice;

switch(choice)

case 1:

insert();

break;

case 2:
deletion();

break;

case 3:

display();

break;

case 4:

exit(0);

break;

default:

cout<<"\n Enter valid choice:";

void insert()

int item;

cout<<"\n Enter the element:";

cin>>item;

if(rear==n-1)

cout<<"\n OVERFLOW";

return;

if(front==-1&&rear==-1)

{
front=0;

rear=0;

else

rear=rear+1;

queue[rear]=item;

cout<<"\n Value inserted";

void deletion()

int item;

if(front==-1||front>rear)

cout<<"\n UNDERFLOW";

return;

else

item=queue[front];

if(front==rear)

front-=-1;

rear=-1;
}

else

front=front+1;

cout<<"\n value deleted";

void display()

int i;

if(rear==-1)

cout<<"\n empty queue";

else

cout<<"\n printing value";

for(i=front;i<=rear;i++)

cout<<queue[i];

You might also like