Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

TElXTree: Index Order corresponds to Pre-Order always?

XTree.Items has an index order for which one uses a for i := 0 to Pred(Count) loop to process.

Is this order always in the order of the visible tree?  

Does this 'for' loop always process the items of the XTree in pre-order?

Does inserting, deleting, moving or exchanging items change the index order?

If an item is deleted with index = 2, are all the items with index > 2 renumbered so that 3 becomes 2, 4 becomes 3, and so on?

Is there anything that can change the pre-order nature of the for-loop?

Thanks

Raymond
Tagged:

Comments

  • 3 Comments sorted by Votes Date Added
  • >>Is there anything that can change the pre-order nature of the for-loop?<<
    For deletion and chaning you avoid any thoughts about this by simply run the loop from the back (Count-1 to 0).  Then you need not to bother about deletion or changing items.
    Multiple operations which can change (insert/move) the position of items? This is definitely no task for a one-time loop. 


  • I don't want to do anything in the for-loop that changes the position of the items.

    Let me explain another way.

    After appending numerous items to the XTree in a pre-order fashion, the fully-open tree will be processed in pre-order with the Index property of Items.

    If the user then moves an item to another position, deletes and item and inserts some before the last child of an item, then it is of concern to me that the new items will have index of Count, Count + 1, ... .

    E.g. Suppose I have the tree

    1
      11
      12
      13
    2
      21
      22

    This is visually in pre-order and if I were to loop from 0 to 7 and display the items, they would appear as

    0: 1
    1: 11
    2: 12
    3: 13
    4: 2
    5: 21
    6: 22

    Now suppose I insert an item, 'A', before position 0:

    A
    1
      11
      12
      13
    2
      21
      22

    Does the first item, 'A', have Index 0 and the others have their previous indexes incremented by 1?
    Does the first item, 'A', have index 7?

    If I then delete item '12', do all the indexes of those that occur after '12' become decremented by 1?

    What if an item is moved to another location? Will the pre-order traversal of the tree be in the same order as the for-loop order of Item[i] for i := 0 to Pred(Count)?

    Is there any situation in which this loop will not produce the pre-order traversal of the tree?

    Thanks.

    Raymond
Sign In or Register to comment.