Поиск по очереди queue
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <iterator>
template<typename T, typename Cont, typename FwdIter>
void queue_to_container(const std::queue<T, Cont>& q, FwdIter iter)
{
typedef T value_type;
std::queue<T> copy_q = q;
while (!copy_q.empty())
{
*iter++ = copy_q.front();
copy_q.pop();
}
}
int main()
{
std::queue<int> q;
q.push(10);
q.push(20);
q.push(30);
std::vector<int> vec(3);
queue_to_container(q, vec.begin());
std::list<int> lst;
queue_to_container(q, std::back_inserter(lst));
std::cout << "Vector: ";
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
std::cout << "List: ";
std::copy(lst.begin(), lst.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
std::cout << "Queue: ";
std::cout << q.front() << " ";
q.pop();
std::cout << q.front() << " ";
q.pop();
std::cout << q.front() << std::endl;
q.pop();
return 0;
}