I am having 3 datasets, say A B and C.
A contains single array of 5 elements. B contains a 2D array and C also contains a 2D array.
A contains 5 elements which are independent of B and C.
for each element in A, an array is associated in B and for each element in that array of B, an array is associated in C.. so i want to store these data sets in a data structure so that selecting an element in A should give appropriate element array in B and selecting an element in that array of B should give an elements of C.. can anybody suggest me one..i am using java programming language to implement this data structure..
I am having 3 datasets, say A B and C. A contains single array
Share
If I understood you correctly, you are looking for a mapping from elements of A to elements of B, and from those to C. The easiest way to achieve this would be to use some
HashMaps, or any other class implementing theMapinterface, for example:This way,
ais just your array A.bmaps the elements fromato lists, which are the rows in your 2D array B. Similarly,cmaps the elements from those rows to lists, which are the rows in C.Alternatively, you could use a single nested
Mapfor all three:This way, the keys in
abccorrespond to your array A. The value to each key is again a map, whose keys are the elements of the row in B corresponding to that element from A. Finally, the values for each of those keys are the rows in C corresponding to those elements in B.Note that the keys in a
Mapare not ordered, so if order is important (for example if you have to iterate over A in any specific order, or if you have to access them by some index) you should go with the first solution. If order is important forbandcas well, you could try this:Here,
a,bandccorrespond directly to your A, B and C (if you know how many elements they will have you can use arrays, too).abandbcthen hold the mapping from each element ofa(orb) to the corresponding indices inb(orc). Note that you will have to updateabandbcwhenever you insert elements intoaorb.Thus, if order is not important, I would recommend the second solution, since this way you do not have to ‘synchronize’
a,bandc.