How to print 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() 
{ 
    queue<int> q; 
    
    q.push(1); 
    q.push(2); 
    q.push(3); 
    q.push(4); 
    q.push(5); 

    printQueue(q);
} 



/*
run:

1 2 3 4 5 

*/

 



answered Apr 5, 2020 by avibootz

Related questions

1 answer 244 views
1 answer 277 views
2 answers 214 views
1 answer 263 views
1 answer 258 views
1 answer 261 views
261 views asked Apr 5, 2020 by avibootz
...