1
我有地圖,有以下數據:如何在地圖中查找上一個和下一個鍵/值?
id prev abundance thing
1573 -1 0 book
1864 1573 39 beds
2075 1864 41 tray
1760 2075 46 cups
的地圖是:
map<int id, Abund*> oldMap;
struct Abund
{
int prev;
int abundance;
string thing;
}
我現在需要創建一個新的地圖,應該是這樣的:
id2 prev2 prevAbun next2 nextAbun thing2
1573 -1 1864 39 book
1864 1573 0 2075 41 beds
2075 1864 39 1760 46 tray
1760 2075 41 cups
地圖1中的上一行和下一行應該成爲新地圖中的列 到目前爲止,我已經創建了一個新地圖和新結構:
struct NewAbund
{
vector<int> prev2;
vector<int> prevAbun;
vector<int> next2;
vector<int> nextAbun;
string thing2;
}
map<int id2, NewAbund*> newMap;
現在我不知道應該如何從oldMap獲取前一行的邏輯工作,並將其作爲值在newMap。提前致謝!!
哦,我沒有意識到std :: next和std :: prev,但是當我使用它時,我得到這個錯誤:'名字空間中沒有命名爲next的成員std' – snazziii
您需要(a)確保您使用的是C++ 11(對於gcc,它是--std = C++ 11或--std = C++ 0x,取決於gcc版本)和(b)#include –
rici
是的!有用!!非常感謝你! – snazziii