我在找出一个可以帮助我在链表中找到多个整数的算法时遇到了麻烦
答案 0 :(得分:0)
希望这有帮助:
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
list<int> mylist;
mylist.push_back(1);
mylist.push_back(4);
mylist.push_back(1);
mylist.push_back(3);
mylist.push_back(4);
mylist.push_back(5);
list<int>::iterator iter;
for( iter = mylist.begin(); iter != mylist.end(); iter++)
{
cout << *iter << endl;
}
for(list<int>::iterator it = mylist.begin(); it != mylist.end(); it++)
{
list<int>::iterator finder = std::find(mylist.begin(), mylist.end(), *it);
while (finder != mylist.end())
{
finder = std::find(++finder, mylist.end(), *it);
if(finder != mylist.end())
{
cout << "catch it" << endl;
cout << * finder;
}
}
}
return 0;
}