private static void InsertRecursive(ref BstItem tree, Item item, int digit) { if (tree == null) { tree = new BstItem(item); return; } if (BstTreeUtils.DigitBit(item.Key, digit)) // текущий бит ключа 1 { InsertRecursive(ref tree.Right, item, digit + 1); } else // текущий бит ключа 0 { InsertRecursive(ref tree.Left, item, digit + 1); } }
private Item SearchDstRecursive(BstItem tree, int key, int digit) { // следуем по дереву, заданному битами ИСКОМОГО/ВСТАВЛЯЕМОГО ключа if (tree == null) { return(null); } if (tree.Item.Key == key) { return(tree.Item); } if (BstTreeUtils.DigitBit(key, digit)) // current bit is 1 { return(SearchDstRecursive(tree.Right, key, digit + 1)); } else // current bit is 0 { return(SearchDstRecursive(tree.Left, key, digit + 1)); } }
public Item Select(int k) { return(BstTreeUtils.SelectRecursive(root, k)); }
public void Remove(Item item) { --count; BstTreeUtils.RemoveRecursive(ref root, item.Key); }