COMPUTER S
AVLTest(1).java

# AVLTest(1).java - import java.util import java.io public...

• Notes
• 4

This preview shows pages 1–2. Sign up to view the full content.

import java.util.*; import java.io.*; public class AVLTest { public static int getdepth(AVLNode node) { int L=0; int R=0; int result=0; if (node!=null) { if (node.left!=null) L=node.left.depth; if (node.right!=null) R=node.right.depth; result=max(L, R)+1; } return result; } public static AVLNode rotateright(AVLNode y) { AVLNode x=y.left; AVLNode T2=x.right; System.out.println("In rotateright y and x are "+y.info+" "+x.info); // Do the rotation x.right=y; y.left=T2; // Update depths y.depth=max(getdepth(y.left), getdepth(y.right))+1; x.depth=max(getdepth(x.left), getdepth(x.right))+1; // Return new node System.out.println("Exiting rotateright"); return x; } public static AVLNode rotateleft(AVLNode y) { AVLNode x=y.right; AVLNode T2=x.left; // Do the rotation x.left=y; y.right=T2; System.out.println("In rotateleft y and x are "+y.info+" "+x.info); // Update depths y.depth=max(getdepth(y.left), getdepth(y.right))+1; x.depth=max(getdepth(x.left), getdepth(x.right))+1; // Return new node return x; } public static void main(String[] args) { AVLNode t=null; int i; Scanner keyboard=new Scanner(System.in); System.out.print("\nEnter positive (insert) integer"); System.out.print(" or negative (delete) integer \n");

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

This is the end of the preview. Sign up to access the rest of the document.
• Fall '16
• James Korsh
• French Revolution, Left-wing politics, Political spectrum, Void type, Database trigger

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern