我无法找出一种算法来帮助我在链表中找到多次出现的整数
问问题
49 次
1 回答
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;
}
于 2014-10-08T06:01:59.573 回答