2014-10-08 63 views

回答

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; 
} 
相關問題