Implementation of Queue using Link List
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 other application of the Stack is same just like that Queue is the FIFO(First In First Out),Non primitive Data Structure ,ADT(Abstract Data Type), Push And Pop Function etc… 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 readBY HaRis
Tags
انفارمیشن