0

Question:write a function append that takes as input two queues Q1 and Q2, appends the content of Q2 to Q1 and returns Q1. The protoype of the function is: queue<float> append(queue<float> Q1, queue<float> Q2);

My problem here im completly stuck i do not understand how to work it.

here are my codes that i have tried atleast but end up with nothing:

#include <iostream>
#include <queue>

using namespace std;

queue<float> append(queue<float> Q1, queue<float> Q2);

int main()
{

float x,y;

  x= 2;

  y=2;



    return 0;
}
queue<float> append(queue<float> Q1, queue<float> Q2)
{

    Q1.append(Q2);

    return Q1;

}

Edited by nitish.mohiputlall: error

2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by jkhippie
0

Try this...

queue<float> append( queue<float> Q1, queue<float> Q2 )
{
    for( int index = 0; index < Q2.size(); index++ )
    {
        Q1.push( Q2.pop() );
    }
    return Q1;
}
0

Oops, the size will change, won't it. So then...

int sz = Q2.size();
for(int index = 0; index < sz; index+ )
    Q1.push( Q2.pop() );
return Q1;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.