[Overview][Types][Classes][Variables][Index] Reference for unit 'AVL_Tree' (#fcl)

TAVLTree.AddAscendingSequence

Declaration

Source position: avl_tree.pp line 120

public function TAVLTree.AddAscendingSequence(

  Data: Pointer;

  LastAdded: TAVLTreeNode;

  var Successor: TAVLTreeNode

):TAVLTreeNode;

Arguments

Data

  

Data to insert

LastAdded

  

Last added node. Must initially be Nil.

Successor

  

Successor node. Must initially be Nil.

Function result

The newly inserted node

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

TAVLTree.Add

  

Add a new node to the tree


Documentation generated on: Jun 23 2021