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

2) Queue Array

The document describes implementing a queue using an array in C++. It defines a Queue class with methods to add, delete, and view all elements. The main function calls a MENU function that allows the user to test the queue by adding, deleting, and viewing elements.

Uploaded by

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

2) Queue Array

The document describes implementing a queue using an array in C++. It defines a Queue class with methods to add, delete, and view all elements. The main function calls a MENU function that allows the user to test the queue by adding, deleting, and viewing elements.

Uploaded by

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

Practical No:- 02

Practical Name:- Implementation of Queue using Array


Name:- ankush bhakare
Roll No:- 14

#include<iostream.h>
#include<conio.h> class
queue
{
int A[6],size,front,rear; public:
queue();
void add(int); int
del(); void viewall();
};
queue::queue()
{
size=5;
front=0; rear=0;
}
void queue::add(int ele)
{
if(rear==size)
{
cout<<"\n Queue is full:";
}
else
{
if(front==0)//while q is empty
front=1; rear=rear+1;
A[rear]=ele;
}
}
int queue::del()
{
int ele; if(front==0)
{
cout<<"\n Queue is empty";
return NULL;
}
else
{
ele=A[front];
if(front==rear)
front=rear=0;
else
front=front+1;
return ele;
}
}
void queue::viewall()
{
int i;
if(front==0)

cout<<"\n Queue is empty";

else
{
for(int i=front;i<=rear;i++)
{
cout<<A[i]<<"";
}
}
}
void MENU()
{
int option,ele;
queue obj; do
{
cout<<"\n select the option:";
cout<<"\n 1.ADD"; cout<<"\n
2.DELETE"; cout<<"\n
3.VIEW_ALL"; cout<<"\n
4.EXIT"; cout<<"\n Enter your
option"; cin>>option;
switch(option)
{
case 1:
cout<<"\n Enter ele to ADD in queue:";
cin>>ele; obj.add(ele); break;
case 2:
ele=obj.del(); if(ele!
=NULL)
cout<<endl<<ele<<"delete"; break;
case 3:
cout<<endl<<"\n the queue element are:";
obj.viewall(); break; case 4:
return;
default:
cout<<endl<<"invalid option:";
}
}while(1);
}
void main()
{
clrscr();
MENU(); getch();
}

You might also like