Queues Implementation using Single Link List
#include <iostream>
using namespace std;
struct Node {
int value;
Node *next;
};
int main(){
int menu;
int sel;
int count=0;
struct Node *p = new Node;
struct Node *head = new Node;
for( int i=0;i<=79;i++){
cout<<'*';
}
cout<<" Built & Designed by Arslan Malik Aareez"<<endl;
cout<<" www.CWorldbyAS.blogspot.com"<<endl;
cout<<" Facebook : www.facebook.com/arslan.ud.din"<<endl;
cout<<" Twitter : www.twitter.com/itsaareez"<<endl;
for( int i=0;i<=79;i++){
cout<<'*';
}
ask:
cout<<"1. Insert\n2. Delete\n3. Print\n4. Exit"<<endl;
cin>>menu;
switch(menu){
case 1:
count++;
cout<<"Enter Value to insert : ";
cin>>p->value;
p->next = NULL;
head = p;
system("cls");
cout<<"Do you want to enter any other value?\n\n1. Yes\n2. No";
cin>>sel;
system("cls");
while (sel!=2){
struct Node *q = new Node;
count++;
cout<<"Enter Value to insert : ";
cin>>q->value;
q->next = NULL;
p->next = q;
p = p->next;
system("cls");
cout<<"Do you want to enter any other value?\n\n1. Yes\n2. No";
cin>>sel;
system("cls");
}
goto ask;
break;
case 2:
count--;
p = head;
head = p->next;
p->value = 0;
p->next = NULL;
system("cls");
goto ask;
break;
case 3:
system("cls");
p = head;
if (count==0){
system("cls");
cout<<"Queue is empty.";
}
else{
cout<<"Your queue has the following values"<<endl;
while (p->next!=NULL){
cout<<" "<<p->value;
p = p->next;
}
cout<<" "<<p->value;
}
cout<<"\n\n";
system("pause");
system("cls");
goto ask;
break;
case 4:
return 0;
break;
}
}
#include <iostream>
using namespace std;
struct Node {
int value;
Node *next;
};
int main(){
int menu;
int sel;
int count=0;
struct Node *p = new Node;
struct Node *head = new Node;
for( int i=0;i<=79;i++){
cout<<'*';
}
cout<<" Built & Designed by Arslan Malik Aareez"<<endl;
cout<<" www.CWorldbyAS.blogspot.com"<<endl;
cout<<" Facebook : www.facebook.com/arslan.ud.din"<<endl;
cout<<" Twitter : www.twitter.com/itsaareez"<<endl;
for( int i=0;i<=79;i++){
cout<<'*';
}
ask:
cout<<"1. Insert\n2. Delete\n3. Print\n4. Exit"<<endl;
cin>>menu;
switch(menu){
case 1:
count++;
cout<<"Enter Value to insert : ";
cin>>p->value;
p->next = NULL;
head = p;
system("cls");
cout<<"Do you want to enter any other value?\n\n1. Yes\n2. No";
cin>>sel;
system("cls");
while (sel!=2){
struct Node *q = new Node;
count++;
cout<<"Enter Value to insert : ";
cin>>q->value;
q->next = NULL;
p->next = q;
p = p->next;
system("cls");
cout<<"Do you want to enter any other value?\n\n1. Yes\n2. No";
cin>>sel;
system("cls");
}
goto ask;
break;
case 2:
count--;
p = head;
head = p->next;
p->value = 0;
p->next = NULL;
system("cls");
goto ask;
break;
case 3:
system("cls");
p = head;
if (count==0){
system("cls");
cout<<"Queue is empty.";
}
else{
cout<<"Your queue has the following values"<<endl;
while (p->next!=NULL){
cout<<" "<<p->value;
p = p->next;
}
cout<<" "<<p->value;
}
cout<<"\n\n";
system("pause");
system("cls");
goto ask;
break;
case 4:
return 0;
break;
}
}