std set 排序,STL排序

  std set 排序,STL排序

  标准模板库集类排序-缘起宇轩阁-博客频道CSDN .网

  标准模板库集类排序

  分类:

  C语言编程

  2011-03-04 19:44

  41人阅读

  评论(0)

  收藏

  举报[升c调]查看plaincopyprint?

  # include set # include string # include iostream using namespace TD;类CEmployee { public:CEmployee();~ ce employee();const string getname()const;void集合名称(conststringname);conststringgetTitle()const;voidsetTitle(字符串标题);intgetID()常量;void setid(intid);private:intm _ id;stringm _ username stringm _ title };CEmployee:CEmployee(){ } CEmployee:~ CEmployee(){ } const string employee:getName()const { returnm _ username;} voice employee:set name(conststringusername){ m _ username=用户名;} const string employee:getTitle()const { returnm _ title;} voice employee:setTitle(string title){ m _ title=title;} intc employee:getID()const { returnm _ id;} voice employee:setID(intid){ m _ id=id;} classsortByID { public:bool operator()(CEmployeeconst _ A,CEmployeeconst _ B)const { if(_ A . getid()_ B . getid())返回trueif(_ a . getid()==_ b . getid())return _ a . getname().compare(_ b . getname())0;返回假的;}};intmain(){set CEmployee,sortByID empIDSet//se是雇员的set,set CEmployee,sort by id:iterator;CEmployeeemployeeInfoemployee信息。集合名称(“employee _ one”);员工信息。设置标题(“雇员”).员工信息。setid(1);empid集。插入(员工信息);CEmployeeemployeeInfo2employee员工信息2。集合名称(“employee _ two”);员工信息2。设置标题(“CFO”);员工信息2。setid(5);empid集。插入(员工信息2);CEmployeeemployeeInfo3employee员工信息3。集合名称(“employee _ three”);员工信息3。设置标题(“经理”);员工信息3。setid(3);empid集。插入(员工信息3);for(ITER=empid集合。begin();iter!=empid集。end();ITER){ cout ITER-getID() ITER-getName() ITER-getTitle()endl;} return0

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: