コード例 #1
0
 private void _insert(int value, Node cur_node)
 {
     if (value < cur_node.getValue())
     {
         if (cur_node.getLeftNode() == null)
         {
             cur_node.setLeftNode(new Node(value));
         }
         else
         {
             this._insert(value, cur_node.getLeftNode());
         }
     }
     else if (value > cur_node.getValue())
     {
         if (cur_node.getRightNode() == null)
         {
             cur_node.setRightNode(new Node(value));
         }
         else
         {
             this._insert(value, cur_node.getRightNode());
         }
     }
     else
     {
         Console.WriteLine("Value already exists in tree.");
     }
 }
コード例 #2
0
 private void _printTree(Node cur_node)
 {
     if (cur_node != null)
     {
         Console.WriteLine(cur_node.getValue());
         _printTree(cur_node.getLeftNode());
         _printTree(cur_node.getRightNode());
     }
 }
コード例 #3
0
 private bool _search(Node cur_node, int value)
 {
     if (cur_node == null)
     {
         return(false);
     }
     if (cur_node.getValue() == value)
     {
         return(true);
     }
     else if (value < cur_node.getValue())
     {
         return(this._search(cur_node.getLeftNode(), value));
     }
     else if (value > cur_node.getValue())
     {
         return(this._search(cur_node.getRightNode(), value));
     }
     else
     {
         return(false);
     }
 }