/*************************************************************************** * Method: addafter * Purpose: * Insert a key in the position already found by tree_search. * Return a pointer to the user's data in the tree. If the value * pointer passed in is null, then we allocate the block, but don't * initialise it to anything. */ public TreeItem addafter(TreeItem place, ulong key, object value ) { if( place == null ){ first = new TreeItem( this, key, value ); return first; } TreeItem child = new TreeItem( this, key, value ); if( child.key < place.key ) place.left = child; /* should go on left leg */ else place.right = child; return child; }
/*************************************************************************** * Method: search * Purpose: * Find an element. If not, find it's correct parent item */ public TreeItem search(ulong key, out TreeItem place) { TreeItem item = getitem( key ); if( item == null ){ place = null; /* no items in tree. set placeholder to null to * indicate insert at top of tree */ return null; /* return null to indicate key not found */ } if( item.key == key ){ place = null; /* found the key already there set pplace to null just for safety */ return item; /* give the user a pointer to his data */ } place = item; /* key was not found - getitem has returned the parent - set this as the place for new insertions */ return null; /* return null to indicate that the key was not found */ }
public Tree() { first = null; }
public TreeItem( Tree rootParam, ulong keyParam, object value ) { root = rootParam; key = keyParam; left = null; right = null; data = value; refCount = 0; }