您的位置:首页 > 编程语言

STL之Set自定义排序

2016-05-23 20:38 232 查看
方法一、以类为比较器
struct classCompare

{

bool operator()(const int& lhs, const int& rhs)

   {

return lhs < rhs ;

}

};

int main(void)

{

set<int, classCompare> aSet ;

system("pause") ;

return 0 ;

}
方法二、以指针函数为比较器
bool fncmp(int lhs, int rhs)

{

return lhs < rhs ;

}


int main(void)

{

bool(*fn_pt)(int, int) = fncmp ;

set<int, bool(*)(int, int)> aSet(fn_pt) ;

system("pause") ;

return 0 ;

}
方法三、在类定义里面重载operator算子(略)采用第一种吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  stl 编程