Hi
I'm currently writing a library which will store items related in a certain way (x is a parent of y, y is a child of z etc).
I'd like to write a function which returns the items within a certain depth (e.g. find all parents no further than 3 levels away). I'd like to return this in a format so that it is clear which items are at which level e.g.
1 2 3
|
Level 1 (direct parent): items z,q
Level 2 (indirect parent): items f,l,i
Level 3 (indirect parent): items k,v,c
|
I've written the function itself but I'm uncertain which data structure to return the result in. Two come to find:
1. a vector of vector<item_type> e.g. the first vector contains (z,q), second (f,l,i) etc
2. a map of <level[int],vector<item_type> e.g. map[3] = k,v,c
I can see the advantages and disadvantages of both. One thing I like about the map is that you start the key at '1' which represents the actual level (unlike vector where the first vector would be [0]).
Comments on either of the above or alternative approaches much appreciated.
Thanks