private BinarySearchTreeNode <K> AddRecursively(BinarySearchTreeNode <K> Current, K Key) { if (Current == null) { return(new BinarySearchTreeNode <K>(Key)); } int CompareResult = Key.CompareTo(Current.Key); if (CompareResult == 0) { return(Current); } if (CompareResult < 0) { Current.Left = AddRecursively(Current.Left, Key); } else { Current.Right = AddRecursively(Current.Right, Key); } return(Current); }
public BinarySearchTreeNode(K Key) { this.Key = Key; Right = null; Left = null; }
private int getSizeRecursively(BinarySearchTreeNode <K> Current) { return(Current == null ? 0 : 1 + this.getSizeRecursively(Current.Left) + this.getSizeRecursively(Current.Right)); }
public void AddNode(K Key) { Root = AddRecursively(Root, Key); }
private int getSizeRecursively(BinarySearchTreeNode <K> Current) { //checked node is present or not if present then it will return 1 for every node and will add at the end return(Current == null ? 0 : 1 + this.getSizeRecursively(Current.Left) + this.getSizeRecursively(Current.Right)); }