开发者

Data structure for a group of grouped data in C++

开发者 https://www.devze.com 2023-03-24 02:28 出处:网络
I need to create a group of grouped data. the size of each internal group is not same. i should be able to access开发者_StackOverflow any member of the any group using indices.

I need to create a group of grouped data. the size of each internal group is not same. i should be able to access开发者_StackOverflow any member of the any group using indices. Which data structure can I use in C++?


If all your data are of the same type you can use a vector of vectors, e.g.

std::vector< std::vector<YourDataType> >


You need to add more information. How are the groups stored? If each group is an array, you can use an array of arrays i.e. (type)**AoA and each index of AoA would point to an array that contains the underlying group. For example:

#include <stdlib.h>

int main()
{
   int group1[3] = {1,2,3};
   int group2[3] = {4,5,6};

   int** groupArray = (int**)malloc(sizeof(int*) *2);
   groupArray[1] = group1;
   groupArray[2] = group2;

   return 0;
}

Since it's C++, a vector of vectors would be a better choice, but the concept is the same. Also, read up on "B-Trees" - it's a good way to store what you're asking for, but that depends on how the groups are themselves stored.

0

精彩评论

暂无评论...
验证码 换一张
取 消