コード例 #1
0
        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);
        }
コード例 #2
0
 public BinarySearchTreeNode(K Key)
 {
     this.Key = Key;
     Right    = null;
     Left     = null;
 }
コード例 #3
0
 private int getSizeRecursively(BinarySearchTreeNode <K> Current)
 {
     return(Current == null ? 0 : 1 + this.getSizeRecursively(Current.Left)
            + this.getSizeRecursively(Current.Right));
 }
コード例 #4
0
 public void AddNode(K Key)
 {
     Root = AddRecursively(Root, Key);
 }
コード例 #5
0
 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));
 }