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

7) Queue Linklist

Uploaded by

indrorv
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)
22 views3 pages

7) Queue Linklist

Uploaded by

indrorv
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/ 3

Practical No:-1.

7
Practical Name:-Implemetation of Queue using Linklist
Name:- ankush bhakare
Roll No:- 14

#include<iostream.h>
#include<conio.h>
class NODE
{
public:
int data;
NODE*link;

};
class QUEUE
{
NODE *front,*rear;
public:
QUEUE();
void ADD_151(int);
int DELETE_151();
void VIEWALL_151();
};
QUEUE::QUEUE()
{
front=NULL;
rear=NULL;
}
void QUEUE::ADD_151(int ele)
{
//step1 create a node
NODE *NN=new NODE();
//step 2 fill
NN->data=ele;
NN->link=NULL;
//step3
if(front==NULL)
{
front=NN;
rear=NN;
}
else
{
rear->link=NN;
rear=NN;
}
}
int QUEUE::DELETE_151()
{
if(front==NULL)
{
cout<<endl<<"QUEUE is empty";
return NULL;

}
else
{
int ele=front->data;
NODE *temp=front;
if(front==rear)
{
front=rear=NULL;
}
else
{
front=front->link;
}
delete temp;
return ele;
}
}
void QUEUE::VIEWALL_151()
{
if(front==NULL)

cout<<"Queue is empty";
else
{
NODE *ptr;
ptr=front;
while(ptr !=NULL)
{
cout<<" "<<ptr->data;
ptr=ptr->link;
}
}
}
void MENU()
{
QUEUE obj;
int ch,ele;
do
{
cout<<endl<<"1.ADD"<<endl;
cout<<"2.DELETE"<<endl;
cout<<"3.VIEWALL"<<endl;
cout<<"4.EXIT"<<endl;
cout<<"Enter your choice:"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter elements"<<endl;
cin>>ele;
obj.ADD_151(ele);
break;
case 2:
ele=obj.DELETE_151();
if(ele!=NULL)
cout<<"deleted element is: "<<ele<<endl;
break;
case 3:
cout<<"Queue Elements are: "<<endl;
obj.VIEWALL_151();
break;
case 4:
return;
default:
cout<<"Invalid choice!";
}

}while(1);

}
void main()
{
clrscr();
MENU();
getch();
}

You might also like