我想实现Java AVL树并左右旋转树.我没有得到这个.
任何人都可以通过查看下面的代码告诉我如何可以左右旋转树,然后使用这两个函数修复以平衡AVL树?
我希望这里有人可以指导我完成这件事.
import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;
public class AVLTree<T> extends
BinarySearchTree<AVLTree.Node<T>, T> implements SSet<T> {
Random rand;
public static class Node<T> extends BSTNode<Node<T>,T> {
int h; // the height of the node
}
public AVLTree() {
sampleNode = new Node<T>();
rand = new Random();
c = new DefaultComparator<T>();
}
public int height(Node<T> u) {
return (u == null) ? 0 : u.h;
}
public boolean add(T x) {
Node<T> u = new Node<T>();
u.x = x; …Run Code Online (Sandbox Code Playgroud)