我有一张包含以下数据的地图:
id prev abundance thing
1573 -1 0 book
1574 1573 39 beds
1575 1574 41 tray
1576 1575 46 cups
我正在编写的代码是这样的:
struct Abund
{
int prev;
int abundance;
string thing;
}
map<int id, Abund*> oldMap;
我现在需要创建一个应该如下所示的新地图:
id2 prev2 prevAbun next2 nextAbun thing2
1573 1574 39 book
1574 1573 0 1575 41 beds
1575 1574 39 1576 46 tray
1576 1575 41 cups
因此,为此我创建了一个新地图和新结构:
struct NewAbund
{
vector<int> prev2;
vector<int> prevAbun;
vector<int> next2;
vector<int> nextAbun;
string thing2;
NewAbund() :
prev2(0),
prevAbun(0),
next2(0),
nextAbun(0),
thing2() {}
NewAbund(
vector<int> nodeprev2,
vector<int> prev_cnt2,
vector<int> nodenext2,
vector<int> next_cnt2,
string node_thing2) :
prev2(nodeprev2), prevAbun(prev_cnt2), next2(nodenext2), nextAbun(next_cnt2), thing2(node_thing2) {}
}
NewAbund(const Abund& old)
{
thing2 = old.thing;
prev2.push_back(old.prev);
prevAbun.push_back(old.abundance);
}
map<int id, NewAbund*> newMap;
现在,我完全不知道如何将元素从一张地图填充到另一张地图。:(