STL set class sorting

Source: Internet
Author: User

# Include <set> <br/> # include <string> <br/> # include <iostream> <br/> using namespace STD; </P> <p> class cemployee {<br/> Public: <br/> cemployee (); <br/> ~ Cemployee (); <br/> const string getname () const; <br/> void setname (const string name); <br/> const string gettitle () const; <br/> void settitle (String title); <br/> int GETID () const; <br/> void setid (int id); <br/> PRIVATE: <br/> int m_id; <br/> string m_username; <br/> string m_title; </P> <p >}; <br/> cemployee: cemployee () <br/>{</P> <p >}< br/> cemployee ::~ Cemployee () <br/>{< br/>}< br/> const string cemployee: getname () const <br/>{< br/> return m_username; <br/>}< br/> void cemployee: setname (const string username) <br/>{< br/> m_username = username; <br/>}</P> <p> const string cemployee: gettitle () const <br/>{< br/> return m_title; <br/>}</P> <p> void cemployee: settitle (String title) <br/>{< br/> m_title = title; <br/>}< br/> int cemployee: GETID () con St <br/>{< br/> return m_id; <br/>}< br/> void cemployee: setid (int id) <br/>{< br/> m_id = ID; <br/>}< br/> class sortbyid <br/>{< br/> public: <br/> bool operator () (cemployee const & _ A, cemployee const & _ B) const <br/>{< br/> If (_. GETID () <_ B. GETID () return true; <br/> If (_. GETID () = _ B. GETID () return _. getname (). compare (_ B. getname () <0; <br/> return false; <br/>}< br/>}; </P> <p> int Ma In () <br/>{< br/> set <cemployee, sortbyid> empidset; // se is an employee's set, <br/> set <cemployee, sortbyid> :: iterator ITER; <br/> cemployee employeeinfo; <br/> employeeinfo. setname ("employee_one"); <br/> employeeinfo. settitle ("employee"); <br/> employeeinfo. setid (1); <br/> empidset. insert (employeeinfo); <br/> cemployee employeeinfo2; <br/> employeeinfo2.setname ("employee_two"); <br/> employeeinfo2.settitle ("CFO"); <br/> employeeinfo2.setid (5); <br/> empidset. insert (employeeinfo2); </P> <p> cemployee employeeinfo3; <br/> employeeinfo3.setname ("employee_three"); <br/> employeeinfo3.settitle ("manager "); <br/> employeeinfo3.setid (3); <br/> empidset. insert (employeeinfo3); </P> <p> for (iter = empidset. begin (); iter! = Empidset. end (); ITER ++) <br/>{< br/> cout <ITER-> GETID () <"" <ITER-> getname () <"" <ITER-> gettitle () <Endl; <br/>}< br/> return 0; <br/>}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.