赞
踩
直接上代码
- #include <string.h>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
-
- int main()
- {
- vector<int>obj;
- //想容器中放东西:obj[0]等于1,obj[1]等于3,obj[0]等于0,
- obj.push_back(1);
- obj.push_back(3);
- obj.push_back(0);
-
- //对容器中的成员进行排序 从小到大
- sort(obj.begin(), obj.end());//从小到大
-
- cout << "从小到大:" << endl;
- //打印方式
- for (int i = 0; i < obj.size(); i++)
- {
- cout << obj[i] << ",";
- }
-
- cout << "\n" << endl;
-
- cout << "从大到小:" << endl;
- reverse(obj.begin(), obj.end());//从大到小
- for (int i = 0; i < obj.size(); i++)
- {
- cout << obj[i] << ",";
- }
- return 0;
- }
亲测 ok
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。