#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
struct node{
char data;
node * next;
};
void queue1();
void queue2();
void queue3();
void queue4();
void concatenate();
node * firstnodeptr1=NULL;
node * lastnodeptr=NULL;
node * firstnodeptr2=NULL;
node * firstnodeptr3=NULL;
node * firstnodeptr4=NULL;
node *finalfirstnodeptr=NULL;
int counter1=1,counter2=1,counter3=1,counter4=1;
void main(){
char ch;
do{
cout<<"enter the choices "<<endl;
cout<<"1. make four different queues using single linked list by "<<endl<<"input of string by user on runtime"<<endl;
cout<<"2. concatenate four queues into one queue"<<endl;
cout<<"3. exit"<<endl;
cout<<"enter the choice"<<endl;
cin>>ch;
switch(ch){
case '1':
queue1();
queue2();
queue3();
queue4();
break;
case '2':
concatenate();
break;
case '3':
exit(0);
break;
default:
cout<<"input entered is invalid"<<endl;
break;
}
}while(ch!=NULL);
_getche();
}
void queue1(){
//*****************************FIRST QUEUE*********************************
cout<<"*************enter the string for the first queue*****************"<<endl;
string input;
getline(cin,input);
node * tempptr = new node;
tempptr->data=input[0];
tempptr->next=NULL;
firstnodeptr1=tempptr;
lastnodeptr=tempptr;
node * temp=NULL;
for(int i =1;i<input.length();i++){
temp = new node;
temp->data=input[i];
temp->next=NULL;
lastnodeptr->next=temp;
lastnodeptr=temp;
counter1++;
}
node *temp1=firstnodeptr1;
for(int i =1;i<=input.length();i++){
cout<<"the data in the queue is "<<temp1->data<<endl;
temp1=temp1->next;
}
}
void queue2(){
//*****************************SECOND QUEUE*********************************
string input2;
cout<<"*************enter the string for the second queue*****************"<<endl;
getline(cin,input2);
node * tempptr = new node;
tempptr->data=input2[0];
tempptr->next=NULL;
firstnodeptr2=tempptr;
lastnodeptr=tempptr;
node * temp=NULL;
for(int i =1;i<input2.length();i++){
temp = new node;
temp->data=input2[i];
temp->next=NULL;
lastnodeptr->next=temp;
lastnodeptr=temp;
counter2++;
}
node *temp1=firstnodeptr2;
for(int i =1;i<=input2.length();i++){
cout<<"the data in the queue is "<<temp1->data<<endl;
temp1=temp1->next;
}
}
void queue3(){
//*****************************THIRD QUEUE*********************************
string input3;
cout<<"*************enter the string for the third queue*****************"<<endl;
getline(cin,input3);
node * tempptr = new node;
tempptr->data=input3[0];
tempptr->next=NULL;
firstnodeptr3=tempptr;
lastnodeptr=tempptr;
node * temp=NULL;
for(int i =1;i<input3.length();i++){
temp = new node;
temp->data=input3[i];
temp->next=NULL;
lastnodeptr->next=temp;
lastnodeptr=temp;
counter3++;
}
node *temp1=firstnodeptr3;
for(int i =1;i<=input3.length();i++){
cout<<"the data in the queue is "<<temp1->data<<endl;
temp1=temp1->next;
}
}
void queue4(){
//*****************************FOURTH QUEUE*********************************
string input4;
cout<<"*************enter the string for the fourth queue*****************"<<endl;
getline(cin,input4);
node * tempptr = new node;
tempptr->data=input4[0];
tempptr->next=NULL;
firstnodeptr4=tempptr;
lastnodeptr=tempptr;
node * temp=NULL;
for(int i =1;i<input4.length();i++){
temp = new node;
temp->data=input4[i];
temp->next=NULL;
lastnodeptr->next=temp;
lastnodeptr=temp;
counter4++;
}
node *temp1=firstnodeptr4;
for(int i =1;i<=input4.length();i++){
cout<<"the data in the queue is "<<temp1->data<<endl;
temp1=temp1->next;
}
}
void concatenate(){
finalfirstnodeptr=firstnodeptr1;
node * temp= finalfirstnodeptr;
while(counter1>=0){
cout<<temp->data;
temp=temp->next;
counter1--;
}
}
Builder_1 -6 Junior Poster in Training
Builder_1 -6 Junior Poster in Training
NathanOliver 429 Veteran Poster Featured Poster
Builder_1 commented: thanks alot man....really grateful for your assistance bro +1
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.