binary-treetreemodel

treemodel js logic architecture (theorical)


I'm really new a tree sctructure and linked list, I'm a facing a theorical problem, let's say I decide to use TreeModel, seeing the sample, you basically will order the tree like:

 Tree
    node 1
         11
         12
          121
          122
    node 2
         21
          211
   ...and so on

Considering the numbers are node's id, how would I manage them once the happen to be 2 or more digits?

   node 10
         101
          1011
          1012
         102
          1021
          1022
           10221

And so on...? using pseudo code, how do I keep the track of this? meaning, I want to get all 3er level nodels of a node? (>100 for the first 9 and >1000 for the rest???) this is actually my question itself.

I would appreciate any clarification.


Solution

  • TreeModel does not depend on any specific node id format, the numbers shown at the library demo page are just for illustrative purposes. Would it cause less confusion if instead of those numbers you had a string id separated by underscores?

    1
        1_1
        1_2
    ...
    10
        10_1
        10_2
    

    Also note that TreeModel was not designed for binary trees and so it does not support in-order traversal.