Print Friendly and PDF
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int front=-1,rear=-1,tss=0,iq,nq,temp;
int *queue=new int[tss];
void menuq();
void createq();
void displayq();
void findeleq();

void enqueueele();
void dequeueele();
int fullq();
int emptyq();
void clearq();
void dltq();
main()
{
menuq();
getch();
}
void menuq()
{ int z=1;
while(z)
{
cout<<"\t\t 1-Create Queue \t\t\n";
cout<<"\t\t 2-Display Queue \t\t\n";
cout<<"\t\t 3-Find Element \t\t\n";
cout<<"\t\t 4-Enqueue Element \t\t\n";
cout<<"\t\t 5-Dequeue Element \t\t\n";
cout<<"\t\t 6-Full Queue \t\t\n";
cout<<"\t\t 7-Empty Queue \t\t\n";
cout<<"\t\t 8-Clear Queue \t\t\n";
cout<<"\t\t 9-Delete Queue \t\t\n";
cout<<"\t\t 10-Exit \t\t\n";
cout<<"Enter you Choice: ";
cin>>nq;
switch(nq)
{
case 1:
createq();
break;
case 2:
if(rear==-1 && front==-1)
{cout<<"Queue is not created yet: ";}
displayq();
break;
case 3:
if(rear==-1 && front==-1)
{
cout<<"Queue is not created yet: ";
}
findeleq();
break;
case 4:
if(rear==-1 && front==-1)
{
cout<<"Queue is not created yet: ";
}
enqueueele();
break;
case 5:
if(rear==-1 && front==-1)
{
cout<<"Queue is not created yet: ";
}
dequeueele();
break;
case 6:
if(rear==-1 && front==-1)
{
cout<<"Queue is not created yet: ";
}
fullq();
break;
case 7:
if(rear==-1 && front==-1)
{
cout<<"Queue is not created yet: ";
}
emptyq();
break;
case 8:
if(rear==-1 && front==-1)

{
cout<<"Queue is not created yet: ";
}
clearq();
break;
case 9:
if(rear==-1 && front==-1)
{
cout<<"Queue is not created yet: ";
}
dltq();
break;
case 10:
//exit(0);
z=0;
break;
default:

cout<<"Invalid Selection: ";
}

getch();
 }
}
void createq()
{
do{
cout<<"Enter size of Queue: ";
cin>>tss;
}

while(tss<1);
do

{
cout<<"How many Value u want: ";
cin>>rear;
}while(rear<1 || rear>tss);
front=0;
for(iq=0;iq<rear;iq++)
{
cout<<"Enter a Value: ";
cin>>queue[iq];}
cout<<"Queue is successfully created..";
}
void displayq()
{
cout<<"Total number in queue is: "<<rear<<"\n";
for(iq=0;iq<rear;iq++)
{
cout<<queue[iq]<<"\n"; }
getch();}
void findeleq()
{
int temp;
cout<<"Enter number to find: ";
cin>>temp;
for(iq=0;iq<nq;iq++)
{
if(temp==queue[iq])
{
cout<<"The number "<<temp<<" is found at position "<<iq;
break;
}
else
{
cout<<"Number is not found";
break;
}

}
getch();

}
int fullq()
{
if(rear==tss)
{

cout<<"Queue is full";
return 1;

}
else
{
cout<<"Queue is not Full";
return 0;
}
getch();
}
void enqueueele()
{
if(rear==tss && front==0)
{
cout<<"queue is full";}
else
{
cout<<"Enter the number: ";
cin>>temp;
queue[rear]=temp;

rear++;
cout<<"Number is sucessfully enqueue";
getch();

}
void dequeueele()
{
if(front==rear)
{
cout<<"Queue is empty "; 
}
else {
front=front;
}
cout<<"\n"<<temp<<" removed from queue ";
}
int emptyq()
{
if(rear==tss)
{

cout<<"Queue is not empty";
return 0;

}
else 

{
cout<<"Queue is still empty";
return 1;

}
getch();

}
void clearq()
{
front=0;rear=0;
cout<<"Queue is clear";
getch();

}
void dltq()
{
front=-1;rear=-1;
cout<<"Queue is deleted:";
getch();

}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: