#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--;
    }
}

Recommended Answers

All 2 Replies

i have to take a single string as input. Using this input string, i have to create
multiple queues in which each queue will comprise of separate word appeared in input string. At the
end, i will again concatenate all queues to a single queue.
Example:
String = “Data Structure and Algo”
Q1 = D → a → t → a
Q2 = S → t → r → u → c → t → u → r → e
Q3 = a → n → d
Q4 = A → l → g → o
At the end concatenate all queues and display them.
Q1 → Q2 → Q3 → Q4

but in which there is a problem
when i run it queue1() function is skipped..
can someone help me with that....

im still writing the concatenate() but please someone help me in the switch problem..how i can overcome that

That's because you have a newline floating in the input buffer from line 32. To get rid of the newline in the buffer you can just put cin.get() after line 32. That should at least get you into the queue1 function.

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.