2011-03-25 85 views
0

我有大量的數據集。我希望使用數組來存儲這些數據。更詳細地說,如何爲3個數據集創建多級MAP

在我的數組中,我想使用3列,如Number number_of_points point_numbers。爲此,我可以創建一個類似mypointstore[][]的數組(例如mypointstore[20][3])。但我的問題是,我想存儲第3列的點數,如20, 1, 32, 9, 200, 12等(mypointstore[0][0]= 1mypointstore[0][1]= 6mypointstore[0][2]={ 20, 1, 32, 9, 200, 12 })。我不知道這種結構使用數組是否可行?如果是這樣,請幫我解決這個問題。

我試圖使用地圖像map<int,int,vector<int>> mypointstore;但我不知道如何插入數據到這張地圖; 我的一些代碼在這裏

map<int,int, vector<int>> mypointstore; 
size=20; 
For (int i=0; i<= size;i++){ 
Int det=0; 
    For (int j=0; j<= points.size();j++){//points is a one of array with my points 
     If (points.at(j)>Z1 && points.at(j) <=Z2){ 
    //Here i want to store i , det and poiznts.at(j) like i in 1st colum, det in 2nd and 
    //pointnumber in 3rd colum) in each step of the loop it take a point                                                 
    //number //which satisfied the if condition so it should be include into my  
    // vector of map 
det++; 
} 
} 
    // at here i want to change total det value into 2nd element of my map so it like (0)(6)(20, 1, 32, 9, 200, 12) 
} 
下一步

類似的過程,以便finaly應該

(0)(6)(20, 1, 32, 9, 200, 12) 
(1)(10)(20, 1, 32, 9, 200, 12, 233, 80, 12, 90) 
(2)(3)(3, 15, 32) 
+0

我整理了一下你的文章,但不是你的代碼。你有幾個錯誤。 ''不''''''不'''''不''''如果''不'''''''''''''',非常差的縮進,太多的'std :: map'模板參數'矢量'不是比較器)。 – 2011-04-06 14:04:30

+0

不,我不知道如何在這裏發佈代碼 – nah 2011-04-08 12:00:23

+0

有一大堆的建議,信息和鏈接到更多的問題在你寫的問題的框的右側。我描述的問題是關於代碼本身。 – 2011-04-08 12:17:21

回答

2

這聽起來像你對我可能要結構的載體,是這樣的:

struct point_data { 
    int number; 
    std::vector<int> point_numbers; 
}; 

std::vector<point_data> points; 

我只放了兩個「列」,因爲(至少據我瞭解)你的number_of_points可能是point_numbers.size()

如果你打算使用number查找數據的其餘部分,那麼你的主意,用一個map會有意義:

std::map<int, std:vector<int> > points; 

你可以使用的,而不是multimap<int, int>map<int, vector<int> >我平時發現後者更容易理解。

+0

+1解密問題:) – 2011-03-25 17:26:59

+0

實際上number_of_points不是一個point_number.size(),對不起,我錯過了第2個循環之後的1行,即條件值Z1和Z2將會改變。 – nah 2011-03-25 17:31:06

+0

@nah:也許@ dark_charlie的(暗含的)建議是對的,你應該編輯這個問題,以便我們有更好的機會確定你真正想要的東西。 – 2011-03-25 17:35:56