0% found this document useful (0 votes)
8 views

Multiple Queue LL

Uploaded by

rahuljand44
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Multiple Queue LL

Uploaded by

rahuljand44
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<bits/stdc++.

h>
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int data, Node* next=nullptr):data(data),next(next){}
};
class Queue{
public:
Node* start;
Node* end;
Queue():start(NULL),end(NULL){}

void enqueue(int n){


Node* temp=new Node(n);
if(start==nullptr){
start=temp;
end=temp;

}else{
end->next=temp;
end=temp;
}
}

void dequeue(){
if(start==NULL){
cout<<"Queue is empty";
return;
}
Node* temp=start;
start=start->next;
delete(temp);

}
void print(){
if(start==NULL){
cout<<"Queue is empty"<<endl;
return;
}
Node* temp =start;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
};
int main(){
int n;
int m;
cin>>n;
cin>>m;
vector<Queue*>vc(n);
for(int i=0;i<n;i++){
vc[i]= new Queue();
}
for(int i=0;i<m;i++){
int p,q;
cin>>p>>q;
vc[q]->enqueue(p);
}
for(int i=0;i<n;i++){
cout<<"Queue "<<i<<": ";
vc[i]->print();
}
}

You might also like