泛型算法11

来源:互联网 发布:守望先锋max录入数据 编辑:程序博客网 时间:2024/06/08 04:00
/*author:Miracledate:2016年3月11日使用find在一个int型的list中寻找值为0的最后一个元素*/#include<iostream>#include<list>#include<algorithm>using namespace std;void function(){int ia[] = { 0, 1, 2, 3, 4, 5, 6, 0, 7, 8, 9 };list<int> ilst(ia, ia + 10);list<int>::reverse_iterator riter;//反向迭代器//寻找值为0的最后一个元素riter = find(ilst.rbegin(), ilst.rend(), 0);//输出结果if (riter != ilst.rend()){cout << " element after the last 0:" << *(--riter) << endl;}else{cout << "no element 0" << endl;}}

0 0
原创粉丝点击