Professional Documents
Culture Documents
#include<iostream>
class Node {
public:
int key;
int data;
Node * next;
Node()
{
key = 0;
data = 0;
next = NULL;
}
Node(int k, int d) {
key = k;
data = d;
next = NULL;
}
};
class Queue_Using_Linked_List
{
public:
Node *front_of_Linked_List;
Node *rear_of_Linked_List;
Queue_Using_Linked_List()
{
front_of_Linked_List = NULL;
rear_of_Linked_List = NULL;
}
bool Queue_is_Empty()
{
if(front_of_Linked_List==NULL && rear_of_Linked_List==NULL)
{
return true;
}
else
{
return false;
}
}
cout<<"NODE INSERTED"<<endl;
}
}
Node* remove_from_Queue()
{
Node *temp=NULL;
if (Queue_is_Empty())
{
cout << "EMPTY QUEUE" << endl;
return NULL;
}
else
{
if(front_of_Linked_List==rear_of_Linked_List)
{
temp=front_of_Linked_List;
front_of_Linked_List = NULL;
rear_of_Linked_List = NULL;
return temp;
}
else
{
temp=front_of_Linked_List;
front_of_Linked_List = front_of_Linked_List->next;
return temp;
}
}
}
void display_Queue()
{
if(Queue_is_Empty())
{
cout << "EMPTY QUEUE" << endl;
}
else
{
cout << "VALUES OF THIS QUEUE ARE :" << endl;
Node *temp=front_of_Linked_List;
while(temp!=NULL)
{
cout<<"("<<temp->key<<","<<temp->data<<")"<<" -> ";
temp=temp->next;
}
cout<<endl;
}
}
};
int main() {
cout<<"\t\t By: Aleeza Anjum"<<endl;
cout<<"\t\t Reg No: 20-CS-101"<<endl;
Queue_Using_Linked_List q;
int option,key, data;
do {
cout<<"\n\n\t\t |----------------------------------------------------------|"<<endl;
cout << "\t\t |OPERATIONS TO PERFORM" <<"SELECT OPTION. ENTER
0 TO EXIT. |" << endl;
cout << "\t\t1.| INSERTION IN LNKED List |"<< endl;
cout << "\t\t2.| DELETION FROM LINKED LIST |" <<
endl;
cout << "\t\t3.| DISPLAY LINKED LIST |" << endl;
cout << "\t\t4.| CLEAR SCREEN |" << endl;
cout<< "\t\t |----------------------------------------------------------|"<<endl;
cin >> option;
break;
case 3:
cout << "DISPLAYING......... " << endl;
q.display_Queue();
cout << endl;
break;
case 4:
system("cls");
break;
default:
cout << "Enter Proper Option number " << endl;
}
return 0;
}