#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;
}
C++ sort 对自定义类型进行排序
最新推荐文章于 2026-04-09 13:58:34 发布
本文介绍了一个使用C++实现的向量排序示例,其中包括定义了一个结构体`Test`来存储整型数据,并通过自定义比较函数`compare`实现了对`std::vector<Test>`容器中元素的排序。
6121

被折叠的 条评论
为什么被折叠?



