c++ - Using stable_sort, when sorting vector of objects -


i have class passanger has variables string name; string station; string ticket; , have class , within class have vector<passanger*> myqueue;

now want use stable_sort sort myqueue. there possibility, how stable_sort, should key, according shall sort myqueue?

std::stable_sort(myqueue.begin(),myqueue.end(), maybesomethingelse() ); ?

yes, need comparator class. this.

 class comparefoo {    public:      bool operator() (const foo* e1, const foo* s2)       {          return e1->name < e2->name; // strict weak ordering required      }  }; 

then pass instantiation of parameter stable_sort.

std::stable_sort(myqueue.begin(), myqueue.end(), comparefoo()); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -