65,211
社区成员
发帖
与我相关
我的任务
分享#include <list>
#include <algorithm>
#include <iostream>
int main() {
using namespace std;
list <int> L;
list <int>::iterator Iter;
L.push_back( 40 );
L.push_back( 20 );
L.push_back( 10 );
L.push_back( 30 );
L.push_back( 0 );
cout << "L = ( " ;
for ( Iter = L.begin( ) ; Iter != L.end( ) ; Iter++ )
cout << *Iter << " ";
cout << ")" << endl;
list <int>::reverse_iterator result;
result = find( L.rbegin( ), L.rend( ), 0 );
if ( result == L.rend( ) )
cout << "There is no 0 in list L.";
else {
cout << "There is a 0 in list L";
if ( ++result != L.rend() )
cout << " and it is followed by a " << *result << ".";
}
cout << endl;
}
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
int x;
list<int> ilist;
while (cin >> x)
ilist.push_back(x);
list<int>::reverse_iterator rlter;
int search(0);
rlter = find(ilist.rbegin(), ilist.rend(), search); // p281/295
cout << *rlter << endl;
cout << *--rlter << endl; // 测试是否是最后一个0而用的;-- 指向 顺序方向的下一个元素
return 0;
}
#include <list>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
list <int> L;
list <int>::iterator Iter;
/*
L.push_back( 40 );
L.push_back( 20 );
L.push_back( 10 );
L.push_back( 30 );
L.push_back( 0 );
*/
int x;
while (cin >> x)
L.push_back(x);
cout << "L = ( " ;
for (Iter = L.begin() ; Iter != L.end() ; Iter++)
cout << *Iter << " ";
cout << ")" << endl;
list <int>::reverse_iterator result;
result = find(L.rbegin(), L.rend(), 0);
if (result == L.rend())
cout << "There is no 0 in list L.";
else
{
cout << "There is a 0 in list L";
if (result != L.rbegin()) // 输出边上的一个值
{
cout << " , and it is surround by " << *--result;
++result;
}
if (++result != L.rend()) // 输出边上的另一个值
{
cout << " and " << *result << endl;
}
}
cout << endl;
return 0;
}
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
int x;
list<int> ilist;
while (cin >> x)
ilist.push_back(x);
list<int>::reverse_iterator rlter;
int search(0);
rlter = find(ilist.rbegin(), ilist.rend(), search); // p281/295
cout << *rlter << endl;
cout << *--rlter << endl; // 测试是否是最后一个0而用的;-- 指向 顺序方向的下一个元素
list<int> ilist2(1);
list<int>::iterator lter = find_end(ilist.begin(), ilist.end(), ilist2.begin(), ilist2.end()); // find_end()查找
cout << *lter << endl;
cout << *++lter << endl;
return 0;
}