c++ - Is there an stl container for this hierarchical model data? -
for platform-independent model layer, have hierarchical data (strings, actually) this:
- item
- subitem a
- subitem b
- subitem c
- subsubitem a
- subsubitem b
- subitem d
- item b
- item c
now, within each "level" (item, subitem, subsubitem, etc.) items need sorted alphabetically.
seems simple solution create simple class sorted std::vector or std::multimap track children, , pointer parent. (and 1 root item). need iterate through each item's children in forward direction.
after construction/sorting, not need add or delete items. small numbers of items (hundreds).
this model organization of backing data of outline-style control.
rolling simple class easy, such common pattern — isn't there ready-made stl container behavior?
nothing in stl itself, might find useful:
tree.hh: stl-like c++ tree class
its api follows stl containers exactly, , should you're looking for.
i believe their example asking (a tree strings), in fact.
Comments
Post a Comment