#include <list>
#include <algorithm>
#include <time.h>
using namespace std;
typedef struct mystruct
{
int a;
int b;
}mystruct;
template<>
struct std::greater<mystruct>
{
bool operator()( mystruct X, mystruct Y) const
{
return X.a == Y.a ? X.b < Y.b : X.a < Y.a;
}
};
void main()
{
list<mystruct> data;
srand((unsigned)time(NULL));
mystruct StrInfo;
for (int i =0; i < 10 ; i ++)
{
StrInfo.a = 1 + rand() % 10;
StrInfo.b = 1 + rand() % 10;
data.push_back(StrInfo);
}
data.sort(greater<mystruct>());
return;
}
本文深入探讨了C++模板元编程的概念及其在标准模板库(STL)中的应用实例,通过实例展示了如何利用模板元编程实现高效、灵活的数据结构与算法设计。
1701

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



