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

Queue ADT Array

The document describes a queue implementation using an array in C++. It defines a Queue class with functions to insert, delete, and display elements. The main() function demonstrates using the queue by inserting and deleting elements and displaying the current elements. The output shows elements being inserted and deleted from the queue as expected.

Uploaded by

MikeSteve
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Queue ADT Array

The document describes a queue implementation using an array in C++. It defines a Queue class with functions to insert, delete, and display elements. The main() function demonstrates using the queue by inserting and deleting elements and displaying the current elements. The output shows elements being inserted and deleted from the queue as expected.

Uploaded by

MikeSteve
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

REG NO:310113106098

QUEUE ADT- ARRAY IMPLEMENTATION

PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class queue
{
int queue1[5];
int rear,front;
public:
queue()
{
rear=-1;
front=-1;
}
void insert(int x)
{
if(rear > 4)
{
cout <<"queue over flow";
front=rear=-1;
return;
}
queue1[++rear]=x;
cout <<"inserted" <<x;
}
void delet()
{
if(front==rear)
{
cout <<"queue under flow";
return;
}
cout <<"deleted" <<queue1[++front];
}
void display()
{
if(rear==front)
{
cout <<" queue empty";
return;
}
for(int i=front+1;i<=rear;i++)
cout <<queue1[i]<<" ";
}
};

REG NO:310113106098

main()
{
clrscr();
int ch;
queue qu;
while(1)
{
cout <<"\n1.insert 2.delete 3.display 4.exit\nEnter ur choice";
cin >> ch;
switch(ch)
{
case 1: cout <<"enter the element";
cin >> ch;
qu.insert(ch);
break;
case 2: qu.delet(); break;
case 3: qu.display();break;
case 4: exit(0);
}
}
return (0);
}

REG NO:310113106098

OUTPUT:
1.insert 2.delete 3.display 4.exit
Enter ur choice1
enter the element21
inserted21
1.insert 2.delete 3.display 4.exit
Enter ur choice1
enter the element22
inserted22
1.insert 2.delete 3.display 4.exit
Enter ur choice1
enter the element16
inserted16
1.insert 2.delete 3.display 4.exit
Enter ur choice3
21 22 16
1.insert 2.delete 3.display 4.exit
Enter ur choice2
deleted21
1.insert 2.delete 3.display 4.exit
Enter ur choice3
22 16
1.insert 2.delete 3.display 4.exit
Enter ur choice

RESULT:

You might also like