c++ class as sort function
2024-08-26 00:18:20
// constructing sets
#include <iostream>
#include <set>
#include <string.h> bool fncomp (int lhs, int rhs) {return lhs<rhs;} struct classcomp {
bool operator() (const int& lhs, const int& rhs) const
{return lhs<rhs;}
}; int main ()
{
std::set<int> first; // empty set of ints int myints[]= {,,,,};
std::set<int> second (myints,myints+); // range std::set<int> third (second); // a copy of second std::set<int> fourth (second.begin(), second.end()); // iterator ctor. std::set<int,classcomp> fifth(second.begin(), second.end()); // class as Compare std::set<int>::reverse_iterator rit;
for (rit=fifth.rbegin(); rit != fifth.rend(); ++rit)
std::cout << ' ' << *rit; //bool(*fn_pt)(int,int) = fncomp;
//std::set<int,bool(*)(int,int)> sixth (fn_pt); // function pointer as Compare //std::cout<<strcmp("abc", "ab")<<std::endl; return ;
}
最新文章
- shiro 实现单用户登录,一个用户同一时刻只能在一个地方登录
- [普通平衡树treap]【学习笔记】
- MVC 分页
- 使用所见即所得文本编辑器编辑文本存入数据库后通过ajax获取服务器json_encode的数据到前台,文本内容上边的html标签不解析
- LESSCSS的几点摘要
- 遍历map的四方方法
- Python常用排序算法
- 多个版本的Python如何设置不冲突
- 基于struts2、hibernate、spring、shiro、MySQL的项目开发
- vue 开发微信小程序
- 使用Struts时,JSP中如何取得各个会话中的参数值?
- 网络对抗课题4.3.1 SQL注入原理与实践
- 每日scrum--No.1
- Python类总结-封装(Property, setter, deleter)
- hdu 5443 The Water Problem(长春网络赛——暴力)
- Java面向对象之异常(自定义异常)
- 293. Flip Game只翻转一步的加减号翻转游戏
- 【转载】BootStrap表格组件bootstrap table详解
- python tensorflow方法手记
- Node.js函数介绍(参数为一个函数)
热门文章
- 【Unity3D】【NGUI】UIRect的Anchor的使用
- response.Close、response.End、response.Flush区别
- CodeForces 501B Misha and Changing Handles(STL map)
- JS JavaScript实现杨辉三角
- 核心动画(UIView封装动画)-转
- 通过匿名管道获取CMD运行结果
- ABAP术语-Company Code
- Vmware+CentOs7+共享目录
- 关于J2EE里面getContextPath()和getRealPath()的区别
- JavaScript -- 继承与原型链