0% found this document useful (0 votes)
7 views2 pages

Cirqular

The document defines a queue class with functions to insert, remove and display queue elements. It includes a main function with a do-while loop to call these functions based on user input choice.

Uploaded by

mithunmp2004
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)
7 views2 pages

Cirqular

The document defines a queue class with functions to insert, remove and display queue elements. It includes a main function with a do-while loop to call these functions based on user input choice.

Uploaded by

mithunmp2004
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
You are on page 1/ 2

#include<iostream.

h>
#include<conio.h>
class queue
{
int item;
struct node
{
int data;
node*link;
}
*front,*rear,*temp,*t,*null;
public:
queue();
void insert();
void remove();
void disp();
};
queue::queue()
{
rear=front=null;
}
void queue::insert()
{
cout<<"enter the data";
cin>>item;
temp=new node;
temp->data=item;
if(front==null)
{
front=rear=temp;
rear->link=front;
}
else
{
rear->link=temp;
rear=temp;
rear->link=front;
}
cout<<"\n inserted";
}
void queue::remove()
{
if(front==null)
{
cout<<"\n queue empty";
}
else
{
if(front==rear)
{
front=rear=null;
}
else
{
t=front;
front=front->link;
rear->link=front;
delete t;
}
cout<<"\n deleted:";
}
}
void queue::disp()
{
if(front==null)
{
cout<<"\n queue empty:";
}
else
{
cout<<"\n queue elements are..";
temp=front;
while(temp!=rear)
{
cout<<"\n"<<temp->data;
temp=temp->link;
}
cout<<"\n"<<temp->data;
}
}
void main()
{
queue ob;
int ch;
clrscr();
do
{
cout<<"\n[1].insert";
cout<<"\n[2].remove";
cout<<"\n[3].disp";
cout<<"\n[4].exit";
cout<<"\n enter your choice[1/2/3/4]";
cin>>ch;
if(ch==1)
ob.insert();
else if(ch==2)
ob.remove();
else if(ch==3)
ob.disp();
}
while(ch!=4);
getch();
}

You might also like