c++ - Sorting both ID and 2 sets of values using STL containers -


i need suggestion use stl containers in best possible way sort 3 sets of data 1. id (integer) 2. first value (string) 3. second value (string)

an example of data structure below:

enter image description here

i want use map sorted @ time of insert , no need execute sorting algorithm separately. since id can repeat must multimap, , each data of column linked each other rows change in order sort keeping same values attached id.

sorting id , value ok, how sort 2 values multimap can take 1 value. thinking multimap of multimap or struct of data structure , stl containers. want make simple possible. need suggestion on how can achieved.

thanks!

having map or set makes sense if , if going many insert/erase operations it. if data structure static, storing vector , sorting once way more effective. said, if understand question correctly, think don't need map, multiset.

typedef pair<int, pair<string, string>> mydatatype;  set<mydatatype> myset; 

here, operator < of pair take care of ordering.

if don't want refer id elem.first, , strings elem.second.first, , elem.second.second, can use struct , overload operator < it.

struct mytype {       int id;      string s1;      string s2;    }; bool operator < (const mytype& t1, const mytype& t2) {     return make_tuple(t1.id, t1.s1, t1.s2) < make_tuple(t2.id, t2.s1, t2.s2); } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -