Skip to content

TAVLTree.AddAscendingSequence

Declaration

Source position: avl_tree.pp line 128

public 
function TAVLTree.AddAscendingSequence(Data: Pointer; 
                                      LastAdded: TAVLTreeNode; 
                                      var Successor: TAVLTreeNode)
                                       : TAVLTreeNode;

Description

AddAscendingSequence is an optimized version of Add for quickly adding an ascending sequence of nodes. It adds Data between LastAdded and Successor as a state and skips searching for an insert position. For nodes with same value the order of the sequence is kept.

It can be used as follows:

LastNode:=nil; // TAvlTreeNode
Successor:=nil; // TAvlTreeNode
for i:=1 to 1000 do
 LastNode:=Tree.AddAscendingSequence(TItem.Create(i),LastNode,Successor);

If LastAdded is Nil a regular add is performed.

Errors

If the nodes are not in ascending order, the tree will not be consistent.

See also

Name Description
TAVLTree.Add Add a new node to the tree.