I think that may not be possible. Your data may be ordered already,
but that does not guerantee that there is not already data inside the
tree that must be ordered "inside" the group you add?

I am thinking of loading a spreadsheet from file. Initially the sheet (= tree) is empty. The cells in the standard spreadsheet files are arranged by rows, starting at the top; and within each row, the cells are ordered from left to right. So, the reader catches the cells in the correct order (the tree sorts the cells exactly in the same way). A standard "Add" of the tree calls "FindInsertPos" which seeks for the correct position of the new cell. But every time this search starts from the root which is unnecessary from my pov because the new cell should be at the end. There is no "Append" or "AddtoEnd" method.

Maybe I should remember the node of the previously added cell, and when the next cell is to be added I should attach it as a right child of this node.

Unfortunately I am not very experienced with this kind of trees. For example: Is it necessary to rebalance the AVLtree immediately after each insertion, or can I wait until all nodes exist? There is a "BalanceAfterInsert" method with the new node as a parameter - this indicates that balancing should occur immediately after insert. But this method is private and thus cannot be called from a derived tree implementing an "AddToEnd" method.
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
http://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to