其他分享
首页 > 其他分享> > list容器反转排序

list容器反转排序

作者:互联网

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

template<class T>
void myPrint(const T &data)
{
   typename T::const_iterator it;

   for(it = data.begin(); it != data.end(); it++)
   {
      cout << *it << endl;
   }
}

int main()
{
   vector<int> v;
   v.push_back(1);
   v.push_back(5);
   v.push_back(3);
   v.push_back(4);

   sort(v.begin(), v.end());
   myPrint(v);

   cout << "--------" << endl;

   list<int> l;
   l.push_back(1);
   l.push_back(5);
   l.push_back(3);
   l.push_back(4);

   l.reverse();
   myPrint(l);

   cout << "--------" << endl;

   l.sort();
   myPrint(l);

   return 0;
}
$ ./a.out     
1
3
4
5
--------
4
3
5
1
--------
1
3
4
5

标签:容器,include,cout,myPrint,list,back,push,排序,data
来源: https://www.cnblogs.com/zhangxuechao/p/16527016.html