#include<iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
class Queue_Linklist{
Node *front;
Node *rear;
public:
Queue_Linklist(){
rear = front = NULL;
}
void insert(int num){
Node *temp = new Node;
temp->data = num;
temp->next = NULL;
if(rear == NULL){
rear = temp;
front = temp;
}
else{
rear->next = temp;
rear = temp;
}
}
int remove(){
int copy = front->data;
Node *del = front;
front = front->next;
if(front == NULL){
rear = NULL;
}
delete del;
return copy;
}
void Display()
{
Node *temp = front;
cout<<"DATA IN QUEUE IS: ";
while(temp != NULL){
cout<<temp->data<<" ";
temp = temp->next;
}
}
};
int main()
{
Queue_Linklist Q;
char choice;
do{
int input;
cout<<"1) TO INSERT NUMBER: \n";
cout<<"2) TO REMOVE NUMBER: \n";
cout<<"33) TO DISPLAY QUEUE: ";
cin>>input;
system("cls");
switch(input){
case 1:{
int num;
cout<<"ENTER NUMBER: ";
cin>>num;
Q.insert(num);
break;
}
case 2:{
cout<<"REMOVED NUMBER IS: "<<Q.remove()<<endl;
break;
}
case 3:{
Q.Display();
break;
}
default:{
cout<<"EROR 404: "<<endl;
break;
}
}
cout<<"\nDO YOU WANT TO CONT...(Y/N)...";
cin>>choice;
system("cls");
}while(choice == 'y');
return 0;
}
Home »
Queue Using Link List
» Queue Using Linked List c++
No comments:
Post a Comment