标签:div eve algo include iter turn 不可 class sort
#include <list> #include <iostream> #include <algorithm> using namespace std; //list反转和排序 void printList(const list<int>&L){ for (list<int>::const_iterator it = L.begin(); it != L.end(); it ++){ cout << *it << ‘ ‘; } cout << endl; } //反转 void test01(){ list<int>L1; L1.push_back(10); L1.push_back(20); L1.push_back(30); L1.push_back(40); cout << "反转前" << endl; printList(L1); L1.reverse(); cout << "反转后" << endl; printList(L1); /* 反转前 10 20 30 40 反转后 40 30 20 10 */ } //排序 void test02(){ list<int>L2; L2.push_back(60); L2.push_back(20); L2.push_back(90); L2.push_back(10); //排序 cout << "排序前" << endl; printList(L2); //sort(L2.begin(), L2.end()); //所有不支持随机访问迭代器的容器,不可以用标准算法 //不支持随机访问地迭代器的容器,内部会提供对应的一些算法 L2.sort(); cout << "排序后" << endl; printList(L2); /* 排序前 60 20 90 10 排序后 10 20 60 90 */ } int main(){ test01(); test02(); return 0; }
标签:div eve algo include iter turn 不可 class sort
原文地址:https://www.cnblogs.com/Iamcookieandyou/p/13169892.html