如何在C++ STL的queue当中查找一个元素?

声明为queue<int> q;待查找元素声明为int num;
2025-01-31 01:20:13
推荐回答(1个)
回答1:

// deque::begin
#include
#include
using namespace std;

int main ()
{
deque mydeque;
deque::iterator it;
int num=3;

for (int i=1; i<=5; i++) mydeque.push_back(i);

cout << "mydeque contains:";

it = mydeque.begin();

while (it != mydeque.end())
if(*it == num)
cout << " " << *it++;

cout << endl;

return 0;
}