0% found this document useful (0 votes)
12 views3 pages

Dynamic Queue Implementation in C++

Uploaded by

muproductions002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Dynamic Queue Implementation in C++

Uploaded by

muproductions002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

><><><><><><><><><><>

//Mariam Ilyas 089 bscs-4a <><><><>Dynamic Queue<><><><>


#include<iostream>
#include<conio.h>
using namespace std;

struct node//for entering values dinamicaly


{
char data;
node* next;

//temperary pointer next


};
class queue
{
node *front;//next initialy null valu
node* rare;

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

~queue()//destructure permentaly deleate(temp memory rame)


{while(front!=NULL)
{
node* temp=front;
front=front->next;
delete temp;
}
}

};//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' : [Link]();break;
case'j' : [Link]();break;
case'k' : [Link]();

}
}while(ch!='l');
getch();
}

You might also like