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;

}

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

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;
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.