【发布时间】:2021-12-12 18:28:05
【问题描述】:
我有以下数据结构(第一个字符串作为学校的“主题”)
map<string, vector<School>> information;
学校是:
struct School {
string name;
string location;
}
我无法按字母顺序(第一个主题,然后是位置,然后是名称)打印整个数据结构。举个例子。
"map key string : struct location : struct name"
"technology : berlin : university_of_berlin"
到目前为止,我设法遍历了初始地图
for (auto const key:information) {
//access to struct
vector<School> v = key.second;
//sorting by location name
//comparasion done by seperate function that returns school.location1 < school.location2
sort(v.begin(), v.end(), compare);
如果我打印出主题 (key.first) 和 v.location,就差不多完成了。地图默认排序,位置比较有效。但我不知道如何按名称添加第二个比较。如果我再次按名称进行排序,那么我会丢失按位置的原始顺序。是否有可能以某种方式“双重排序”,其中一个标准更重要,然后另一个?
【问题讨论】: