I can not get the rotate and add tests to pass in my AVL Tree program. Both
Fantastic news! We've Found the answer you've been seeking!
Question:
I can not get the rotate and add tests to pass in my AVL Tree program. Both of the ways to write the rotate methods that I put in the code block do not work. Please tell me what I can do to pass them.
public BSTNode rotateLeft(BSTNode node) { BSTNode rightChild = node.getRight(); node.setRight(rightChild.getLeft()); rightChild.setLeft(node); updateHeight(node); updateHeight(rightChild); return rightChild; } public BSTNode rotateRight(BSTNode node) { if (node == null) { // if the node is null, return null throw new NullPointerException(); BSTNode x = y.left; BSTNode T2 = x.right; // Perform rotation x.right = y; y.left = T2; // Update heights y.height = Math.max(height(y.left), height(y.right))+1; x.height = Math.max(height(x.left), height(x.right))+1; return x; }
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: