0
if I have a queue class that uses nodes and I want to overload the + operator to add a queue to another queue.
Help me! How could I do it?
1 Resposta
+ 1
#include <iostream>
#include <queue>
using namespace std;
class Queue
{
private:
std::queue<int> que;
public:
// Insertion operator to add it to queue
void operator +(Queue& qu);
void add_Node(int);
void disp();
};
void Queue::add_Node(int a)
{
que.push(a);
}
void Queue::operator+(Queue& tqu)
{
std::queue<int>tmpque;
int n = tqu.que.size();
tmpque = tqu.que;
while(n)
{
que.push(tmpque.front());
tmpque.pop();
n--;
}
}
void Queue::disp()
{
std::queue<int>tmpque;
tmpque = que;
int n = que.size();
cout<<"Queue List "<<endl;
while(n)
{
cout<< tmpque.front()<<"\t";
tmpque.pop();
n--;
}
cout<<endl;
}
int main()
{
Queue q1;
q1.add_Node(2);
q1.add_Node(3);
q1.add_Node(4);
q1.disp();
Queue q2;
q2.add_Node(1);
q2.add_Node(5);
q2.disp();
q1+q2;
q1.disp();
Queue q3;
q3.add_Node(41);q3.add_Node(51);q3.add_Node(61);
q2+q3;
q2.disp();
return 0;
}