C++ sort 对自定义类型进行排序

来源:互联网 发布:php 源码 owncloud 编辑:程序博客网 时间:2024/04/30 13:20
#include "stdafx.h"#include <vector>#include <Windows.h>#include <iostream>#include <algorithm>using namespace std;struct Test{int A;Test(int a){A = a;}};bool compare( Test a, Test b ){return a.A > b.A;}int _tmain(int argc, _TCHAR* argv[]){vector<Test> T1;Test test = Test(1);T1.push_back( test );Test test2 = Test(2);T1.push_back( test2 );sort( T1.begin(), T1.end(),compare );system("pause");return 0;}


0 0