#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int data;
node *next;
};
class queue
{
node *front,*rear;
public:
queue()
{
front=NULL;
rear=NULL;
}
void insert(int data)
{
node *p=new node;
p->data=data;
p->next=NULL;
if(rear==NULL)
{
front=p;
rear=p;
}
else
{
rear->next=p;
rear=p;
}
}
void del()
{
node *t=front;
if(front==NULL)
cout<<"Queue Empty";
else
{
cout<<"The element to be deleted is"<<front->data;
if(front==rear)
front=rear=NULL;
else
{
front=front->next;
delete t;
}
}
}
void display()
{
node *t=front;
if(front==NULL)
cout<<"Queue Empty";
else
{
while(t)
{
cout<<t->data<<" ";
t=t->next;
}
}
}
};
void main()
{
clrscr();
queue q;
int data,option;
while(1)
{
cout<<"\n 1.Insert \n 2.Delete \n 3.Display\n 4.Exit\n Enter your Option";
cin>>option;
switch(option)
{
case 1:
cout<<"\nEnter the element to be inserted";
cin>>data;
q.insert(data);
break;
case 2:
q.del();
break;
case 3:
q.display();
break;
case 4:
exit(0);
}
}
}
#include<conio.h>
#include<process.h>
struct node
{
int data;
node *next;
};
class queue
{
node *front,*rear;
public:
queue()
{
front=NULL;
rear=NULL;
}
void insert(int data)
{
node *p=new node;
p->data=data;
p->next=NULL;
if(rear==NULL)
{
front=p;
rear=p;
}
else
{
rear->next=p;
rear=p;
}
}
void del()
{
node *t=front;
if(front==NULL)
cout<<"Queue Empty";
else
{
cout<<"The element to be deleted is"<<front->data;
if(front==rear)
front=rear=NULL;
else
{
front=front->next;
delete t;
}
}
}
void display()
{
node *t=front;
if(front==NULL)
cout<<"Queue Empty";
else
{
while(t)
{
cout<<t->data<<" ";
t=t->next;
}
}
}
};
void main()
{
clrscr();
queue q;
int data,option;
while(1)
{
cout<<"\n 1.Insert \n 2.Delete \n 3.Display\n 4.Exit\n Enter your Option";
cin>>option;
switch(option)
{
case 1:
cout<<"\nEnter the element to be inserted";
cin>>data;
q.insert(data);
break;
case 2:
q.del();
break;
case 3:
q.display();
break;
case 4:
exit(0);
}
}
}