0% found this document useful (0 votes)
6 views3 pages

Practical-8 & 9 Aim: Implement Insert and Delete Algorithms of Queue Using Array. Input

The document outlines a C++ program that implements queue operations (insert, delete, display) using an array with a maximum size of 5. It includes a user interface for selecting operations and handles queue overflow and underflow conditions. The program continuously prompts the user until they choose to exit.

Uploaded by

patel.shivam1712
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)
6 views3 pages

Practical-8 & 9 Aim: Implement Insert and Delete Algorithms of Queue Using Array. Input

The document outlines a C++ program that implements queue operations (insert, delete, display) using an array with a maximum size of 5. It includes a user interface for selecting operations and handles queue overflow and underflow conditions. The program continuously prompts the user until they choose to exit.

Uploaded by

patel.shivam1712
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/ 3

PRACTICAL-8 & 9

AIM : Implement insert and delete algorithms of queue using array.

INPUT:

#include<iostream.h>
#include<conio.h>
#define maxsize 5
#include<stdlib.h>
int front=-1,rear=-1;
int q[5];
void insert(int);
void delet();
void display();
void main()
{
int choice,item;
clrscr();
while(1)
{
cout<<"Choose any of the operation by writing their number :";
cout<<"\n1)insert\n2)delete\n3)Display\n4)Exit\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter element:";
cin>>item;
insert(item);
break;

case 2:
delet();
break;

case 3:
display();

Data structure and algorithm (4330704) Enrollment No : 239830331099


break;

case 4:
exit(0);
getch();

default:
cout<<"Invalid choice!";
break;
}
}
getch();
}
void insert(int item)
{
if(rear >= 4)
{
cout<<"Queue Overflow\n";
getch();
return;
}
rear++;
q[rear] = item;
if(front == -1)
{
front = 0;
}
}
void delet()
{
int item;
if(front == -1)
{
cout<<"Queue Underflow\n";
getch();
return;
}
item=q[front];
if(front == rear)

Data structure and algorithm (4330704) Enrollment No : 239830331099


{
front = rear = -1;
}
else
{
front++;
}
cout<<"deleted item is :"<<item<<endl;
}
void display()
{
int i;
if(front == -1)
{
cout<<"Empty Queue\n";
return;
}
cout<<"Queue is";
for(i=front;i<=rear;i++)
{
cout<<q[i];
}
getch();
}
OUTPUT:

Data structure and algorithm (4330704) Enrollment No : 239830331099

You might also like