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
Post a Comment