AVLTree - public class AVLTree extends DBSTree cfw_ public...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
public class AVLTree extends DBSTree { public AVLTree(){ super(); } public void add(Comparable item) throws StructureFullException{ p if (isFull()) throw new StructureFullException("The Tree is Full"); i if (isEmpty()) root = new AVLNode(item); else place(root,item); p calculateBalanceFactors((AVLNode)root); c if (!((AVLNode)root).isBalanced()) { System.out.println("rotations"); root = performRotations((AVLNode)root); } } public AVLNode performRotations(AVLNode node){ p if (node.getBalanceFactor()==2){ i AVLNode rightChildNode = (AVLNode)node.getRightNode(); A if (rightChildNode.getBalanceFactor()==-1) i node.setRightNode(rightRotation(rightChildNode));// right rotation at right child node r AVLNode output = leftRotation(node); calculateBalanceFactors(output); return output; r } if (node.getBalanceFactor()==-2){ i AVLNode leftChildNode = (AVLNode)node.getLeftNode(); A if (leftChildNode.getBalanceFactor()==1) i node.setLeftNode(leftRotation(leftChildNode));// left rotation at left child node r AVLNode output = rightRotation(node); A calculateBalanceFactors(output); return output; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} return node;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/26/2010 for the course COMPUTER S Java2 taught by Professor Kwstasmixail during the Spring '10 term at Technical University of Crete.

Page1 / 6

AVLTree - public class AVLTree extends DBSTree cfw_ public...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online