Example #1
0
 void insert(int d) {
   TN p = new TN(d);
   if (root == null) root = p;
   else {
     TN nd = root, q = null;
     while (nd != null) {
       q = nd;
       if (d < nd.val) nd = nd.left;
       else nd = nd.right;
     }
     if (q.val > d) q.left = p;
     if (q.val <= d) q.right = p;
   }
 }