qfedu-cpp-level/day10/stl_list_demo/d4.cpp

33 lines
580 B
C++

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
template <typename T>
void print(const list<T> &lst)
{
for (typename list<T>::const_iterator it = lst.begin(); it != lst.end(); ++it)
cout << *it << ' ';
cout << endl;
}
int main()
{
string s = "abcdefg";
list<char> l(s.begin(), s.end());
print(l);
l.reverse(); // 逆序
print(l);
int m[] = {6, 4, 2, 0, 8, 6, 4};
list<int> l2(m, m + 7);
print(l2);
l2.sort(); // 排序
print(l2);
l2.reverse(); // 逆序
print(l2);
return 0;
}