Answers for "print all elements in queue c++"

C++
0

print queue c++

#include <queue>
#include <iostream>

void print_queue(std::queue q)
{
  while (!q.empty())
  {
    std::cout << q.front() << " ";
    q.pop();
  }
  std::cout << std::endl;
}

int main()
{
  std::queue<int> q;
  for (auto i : {1,2,3,7,4,9,7,2,4}) q.push(i);
  print_queue(q);
}
Posted by: Guest on January-21-2021

Code answers related to "print all elements in queue c++"

Browse Popular Code Answers by Language