Implementation of linear Queue in C++

Implementation of single[two ended],(simple),linear Queue in C++ using Arrays ans classes "

#include<iostream.h>
#include<conio.h>
class queue{
private:
int front,rear,max;
int *queuearr;
public:
queue()
{
cout<<"\nEnter the size of Queue: ";
cin>>max;
front=0,rear=-1;
int *Queue=new int[max];
}
void push(int n)
{
if(rear==max)
cout<<"\nQueue is full\n";
else
rear=rear+1;
queuearr[rear]=n;
}
void pop()
{
if(front==-1 && rear==-1)
cout<<"\nQueue is empty\n";
else
cout<<"\nThe Queue element "<<queuearr[front]<<" is poped\n";
for(front=0;front<rear;front++)    {
queuearr[front]=queuearr[front+1]; }rear=rear-1;
}
void display()
{

for(int i=0;i<=rear;i++)
cout<<"\nvalue is :"<<queuearr[i];
}
};
void main()
{
clrscr();
int a=0,value=0;
queue obj;
while(getch()!=27)
{
cout<<"\n \n\n\t\tSelect an option:\n 1   for Insert\n 2   for Delete\n 3   for Display ";
cin>>a;
clrscr();
switch(a)
{
case 1:
{
cout<<"\nEnter value for index: ";
cin>>value;
obj.push(value);
break;
}
case 2:
obj.pop();
break;
case 3:
obj.display();
break;
}
cout<<"\n\n\t   || Press Esc Key to exit || Any Key For next Operation  ||";
}

}



No comments

Powered by Blogger.