//================================================================================ private CajAvlTreeNode Insert(long key, CajAvlTreeNode node) { if (node == null) { CajAvlTreeNode newNode = new CajAvlTreeNode(); newNode.key = key; return(newNode); } if (key < node.key) { node.left = Insert(key, node.left); } else { if (isUniqueKeys && key == node.key) { //throw exception? } else { node.right = Insert(key, node.right); } } node = node.Balance(); return(node); }
//================================================================================ private CajAvlTreeNode DeleteMin(CajAvlTreeNode node) { if (node.left == null) { return(node.right); } node.left = DeleteMin(node.left); node = node.Balance(); return(node); }
//================================================================================ private CajAvlTreeNode Delete(int key, CajAvlTreeNode node) { if (node == null) { return(null); } if (key < node.key) { node.left = Delete(key, node.left); } else if (key > node.key) { node.right = Delete(key, node.right); } else { CajAvlTreeNode q = node.left; CajAvlTreeNode r = node.right; if (r == null) { return(q); } CajAvlTreeNode min = r.GetMin(); min.right = r.DeleteMin(r); min.left = q; min = min.Balance(); return(min); } node = node.Balance(); return(node); }