Implementation of Queue using Link List
Today we will discussed about the “Implementation of Queue using Link list”. Do you remember that we learn about the Link list in our last tutorial as well as Queue using Array. If you remember that Queue is just like a straight Pipe that have two ends. The insertion end of this pipe From Rare and deletion end from Front side.
In “Implementation of Queue using Link list” we always use the circular Queue not use the simple Queue.
Circular Queue means that If the our Rare side is full of data and we delete some data from Front side the or Program is automatically adjust the Rare side from last to one. Circular Queue is just like as….
The Queue using Link list just like as….
The Program of Queue using Link List
#include<iostream>
using namespace std;
struct node
{
int data;
struct node *link;
};
class Queue
{
private:
struct node *f,*R,*t;
public:
Queue()
{
f=NULL;
R=NULL;
}
int tra()
{
t=f;
while(t!=NULL)
{
cout<<t->data<<endl;
t=t->link;
}
}
int insert()
{
t=new node;
cout<<“\tEnter the values\t”;
cin>>t->data;
if(f==NULL)
{
t->link=NULL;
f=t;
R=t;
}
else
{
t->link=NULL;
R->link=t;
R=t;
}
}
int delect()
{ if (f==NULL)
cout<<“\tQueue is empty\t”<<endl<<endl;
else
f=f->link;
}
};
int main()
{ char y;
Queue a;
do
{
cout<<“\tWant to inert the data and delect the data in Queue [‘i’,’d’]\t”;
cin>>y;
if(y==’i’)
{
a.insert();
a.tra();
}
else if(y==’d’)
{
a.delect();
a.tra();
}
else
cout<<“\t \tInvailed Selection”<<endl;
cout<<“Want to prform more operations [y/N]”<<endl;
cin>>y;
}while(y==’y’);
}
you may also like to read Implementation of Stack using Link list Briefly Program in c++.