std::sort多关键字排序
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct MultiData
{
int a;
int b;
int c;
};
struct ICmpMuls
{
bool operator()(const MultiData& first, const MultiData& second) const
{
if(first.a< second.a)return true;
if(first.a== second.a)
if(first.b< second.b)return true;
if(first.b== second.b)
if(first.c< second.c)return true;
return false;
}
};
int main(int argc, char* argv[])
{
vector<MultiData> vec_muls;
for (int i = 0; i < 300; ++i)
vec_muls.push_back(MultiData(rand()%20, rand()));
sort(vec_muls.begin(), vec_muls.end(), ICmpMuls());
for (size_t s = 0; s < vec_muls.size(); ++s)
cout<<s<<": "<<vec_muls[s].login<<" / "<<vec_muls[s].order<<endl;
return 0;
}
posted on 2011-07-25 16:08
扬州炒饭 阅读(872)
评论(0) 编辑 收藏 引用 所属分类:
STL源码剖析笔记