如何为3个数据集创建多级MAP

问题描述:

我有大量的数据集。我希望使用数组来存储这些数据。更详细地说,如何为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

这听起来像你对我可能要结构的载体,是这样的:

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