Exemple #1
0
 public void Search(int n)
 {
     if (root == null)
     {
         Console.WriteLine("못찾았습니다.");
     }
     else             // root != null
     {
         BinarySearchTreeNode search = root;
         while (true)
         {
             if (n == search.val)
             {
                 Console.WriteLine("찾았습니다.");
                 break;
             }
             else if (n < search.val)
             {
                 if (search.left != null)
                 {
                     search = search.left;
                 }
                 else                         // search.left == null
                 {
                     Console.WriteLine("못찾았습니다.");
                     break;
                 }
             }
             else if (search.val < n)
             {
                 if (search.right != null)
                 {
                     search = search.right;
                 }
                 else                         // search.right == null
                 {
                     Console.WriteLine("못찾았습니다.");
                     break;
                 }
             }
         }
     }
 }
Exemple #2
0
 public BinarySearchTreeNode(int _val)
 {
     val   = _val;
     left  = null;
     right = null;
 }
Exemple #3
0
 public BinarySearchTree()
 {
     root = null;
 }
Exemple #4
0
 public BinarySearchTreeNode()
 {
     left  = null;
     right = null;
 }