コード例 #1
0
 public int GetMaxRecursive(BstNode currentNode)
 {
     if (currentNode.Right == null)
         return currentNode.Data;
     var data = GetMaxRecursive(currentNode.Right);
     return data;
 }
コード例 #2
0
 public int GetMinRecursive(BstNode currentNode)
 {
     if (currentNode.Left == null)
         return currentNode.Data;
     var data = GetMinRecursive(currentNode.Left);
     return data;
 }
コード例 #3
0
 public int GetTreeHeight(BstNode currentNode)
 {
     if (currentNode == null)
         return -1;
     var left = GetTreeHeight(currentNode.Left);
     var right = GetTreeHeight(currentNode.Right);
     var max = Math.Max(left, right) + 1;
     return max;
 }
コード例 #4
0
 public void InOrderTraversal(BstNode currentNode, IList<int?> list)
 {
     if (currentNode != null)
     {
         PreOrderTraversal(currentNode.Left, list);
         list.Add(currentNode.Data);
         PreOrderTraversal(currentNode.Right, list);
     }
 }
コード例 #5
0
 public static bool IsBinarySearchTree(BinarySearchTree tree, BstNode node, int value)
 {
     return false;
 }
コード例 #6
0
        private BstNode DeleteRecursive(BstNode currentNode, int data)
        {
            if (currentNode.Data == data)
            {

            }
            return currentNode;
        }
コード例 #7
0
 private void BalanceTree(BstNode node)
 {
 }
コード例 #8
0
 public int Min(BstNode node, int value)
 {
     if (node == null)
     {
         return int.MaxValue;
     }
     var leftMin = Min(node.Left, node.Data);
     var rightMin = Min(node.Right, node.Data);
     var min = Math.Min(leftMin, rightMin);
     var min2 = Math.Min(min, node.Data);
     var min3 = Math.Min(min2, value);
     return min3;
 }
コード例 #9
0
 public BstNode InsertRecursive(BstNode currentNode, int data)
 {
     if (currentNode == null)
     {
         currentNode = new BstNode { Data = data };
         if (Root == null)
             Root = currentNode;
     }
     else if (data <= currentNode.Data)
     {
         currentNode.Left = InsertRecursive(currentNode.Left, data);
     }
     else if (data > currentNode.Data)
     {
         currentNode.Right = InsertRecursive(currentNode.Right, data);
     }
     return currentNode;
 }