Пример #1
0
 public static void main(String[] args) {
   BNode root1 = new BNode(100);
   root1.left = new BNode(50);
   root1.right = new BNode(300);
   root1.left.left = new BNode(20);
   root1.left.right = new BNode(70);
   List<Integer> first = new ArrayList<Integer>();
   storeInorder(root1, first);
   System.out.println(first);
 }
  public static void main(String[] args) {
    BNode root = new BNode(10);

    root.left = new BNode(8);
    root.right = new BNode(2);

    root.left.left = new BNode(3);
    root.left.right = new BNode(5);
    root.right.left = new BNode(2);
    System.out.println(childrenSumProperty(root));
  }
  /** Used class variable to increment, find efficient one with local variable */
  protected BNode getBSTFromPreOrder(int[] preOrder, int min, int max) {

    if (index >= preOrder.length) {
      return null;
    }
    BNode root = null;

    if (preOrder[index] > min && preOrder[index] < max) {
      root = new BNode(new Data(preOrder[index]));
      index++;
      root.left = getBSTFromPreOrder(preOrder, min, root.data.value);
      root.right = getBSTFromPreOrder(preOrder, root.data.value, max);
    }
    return root;
  }
Пример #4
0
 private void searchB(final int maxALength, final int maxBLength) {
   stackB[0].length = 0;
   stackB[0].turnIndex = 0;
   int d = 0;
   do {
     while (stackB[d].length < maxBLength) {
       final BNode node = stackB[d];
       if (node.turnIndex >= node.turns.length) {
         if (--d < 0) return;
       } else {
         final Turn userTurn = node.turns[node.turnIndex++];
         node.userTurn = userTurn;
         final Turn cubeTurn = SymTransform.getTurn(userTurn, node.symmetry);
         node.cubeTurn = cubeTurn;
         final int length = node.length + metric.length(userTurn);
         if (cubeTurn.isB() && maxALength + length <= maxSearchLength && length <= maxBLength) {
           final BNode nextNode = stackB[d + 1];
           final int mep = transformB.mEdgePosTable.turn(cubeTurn, node.mEdgePos);
           final int cp = transformB.cornerPosTable.turn(cubeTurn, node.cornerPos);
           bprn++;
           if (bprn % CYCLES_BETWEEN_USER_CHECK == 0 && (isInterrupted = reporter.shouldStop()))
             return;
           final int mep_cp_d =
               pruneB.get_mEdgePos_cornerPos_dist(node.mEdgePos_cornerPos_dist, mep, cp);
           if (mep_cp_d <= maxBLength - length) {
             final int udep = transformB.udEdgePosTable.turn(cubeTurn, node.udEdgePos);
             final int mep_udep_d =
                 pruneB.get_mEdgePos_udEdgePos_dist(node.mEdgePos_udEdgePos_dist, mep, udep);
             if (mep_udep_d <= maxBLength - length) {
               nextNode.setCubeState(mep, cp, udep);
               nextNode.setDists(mep_cp_d, mep_udep_d);
               nextNode.setTurnState(node, userTurn, turnListB);
               nextNode.length = length;
               d++;
             } else bpry++;
           } else bpry++;
         }
       }
     }
     stackBSize = d--;
     display();
     maxSearchLength = maxALength + maxBLength - (findAll ? 0 : 1);
   } while (!isInterrupted && d >= 0);
 }
Пример #5
0
  private boolean innerInsert(T t, BNode<T> node) {
    int compare = t.compareTo(node.getValue());
    if (compare < 0) {
      if (node.hasLeftLeaf()) {
        return innerInsert(t, node.getLeftLeaf());
      } else {
        node.setLeftLeaf(new BNode(t));
        return true;
      }
    } else if (compare > 0) {
      if (node.hasRightLeaf()) {
        return innerInsert(t, node.getRightLeaf());
      } else {
        node.setRightLeaf(new BNode(t));
        return true;
      }
    }

    // duplicate value
    return false;
  }
Пример #6
0
 public void setRight(BNode right) {
   this.right = right;
   right.parent = this;
 }
Пример #7
0
 public void setLeft(BNode left) {
   this.left = left;
   left.parent = this;
 }