Dynamic Queue
Dynamic Queue
><><><><><><><><><><>
public:
queue()
{ //in class two temp pointer
front=NULL;//for dynamic null otherwise zero (otherwise they will
point to one another)
rare=NULL;
}
void enque()
{
node* temp =new node;
cin>>temp->data;
temp->next=NULL;
if(rare==NULL)
{
rare=temp;
front=temp;
}
else
{
rare->next=temp;
rare=temp;
}
}//end of enque
void dequeue()
{
if(front==NULL)
{
cout<<"QUEUE IS EMPTY"<<endl;
}
else
{
node* temp =front;
cout<<front->data;
front=front->next;
delete temp;
}
}//end of pop
void Display()
{node* temp=front;
while(temp!=NULL)
{
cout<<temp->data<<endl;
temp=temp->next;
}
}//end of display
};//end of class
void main()
{
queue obj; char ch;
do
{
cout<<"\n\ti. enqueue\n\tj. dequeue\n\tk. Display\n\t l. quit ";
cin>>ch;
switch(ch)
{
case'i' : obj.enque();break;
case'j' : obj.dequeue();break;
case'k' : obj.Display();
}
}while(ch!='l');
getch();
}