How to move queue to another queue in C++

1 Answer

0 votes
#include <iostream>
#include <queue>
  
using namespace std; 

void printQueue(queue<int>& q) { 
    while (!q.empty()) { 
        cout << q.front() << " "; 
        q.pop(); 
    } 
} 
    
int main() 
{ 
    auto it = {1, 2, 3, 4, 5};
    queue<int> q1(it);
    queue<int>q2(move(q1));
    
    cout << "q1" << endl;
    printQueue(q1);
    
    cout << "q2" << endl;
    printQueue(q2);
} 
  
  
  
  
/*
run:
  
q1
q2
1 2 3 4 5 
  
*/

 



answered Apr 5, 2020 by avibootz

Related questions

2 answers 118 views
2 answers 229 views
229 views asked May 5, 2020 by avibootz
3 answers 287 views
1 answer 248 views
1 answer 194 views
1 answer 225 views
2 answers 234 views
...