Пример #1
0
    private AVLTreeNode singleRotateRight(AVLTreeNode node) {
      AVLTreeNode parent_node = (AVLTreeNode) node.getParentNode();
      AVLTreeNode swap_node = (AVLTreeNode) node.getRightChild();
      node.setRightChild(swap_node.getLeftChild());
      swap_node.setLeftChild(node);
      node.setDepth(max(node.getLeftChildDepth(), (node.getRightChildDepth() + 1)));
      swap_node.setDepth(max(swap_node.getRightChildDepth(), (node.getDepth() + 1)));

      if (parent_node == null) {
        swap_node.setParentNode(parent_node);
      } else {
        if (parent_node.getLeftChild() == node) {
          parent_node.setLeftChild(swap_node);
        } else {
          parent_node.setRightChild(swap_node);
        }
      }

      return swap_node;
    }
Пример #2
0
 private AVLTreeNode doubleRotateLeft(AVLTreeNode node) {
   node.setLeftChild(singleRotateRight((AVLTreeNode) node.getLeftChild()));
   return singleRotateLeft(node);
 }