budget/src/main/java/budget/backend/structures/AVLSearchTree.java
private void reorderTree(AVLTreeNode<K,V> parent){
		//Find the unbalanced grandchild by finding the unbalanced child first. With this method, we get three nodes and four other subtrees. From here, depending on the alignment of the three nodes, four different cases can occur
		AVLTreeNode<K,V> child = null;
		if (parent.balanceFactor() > 1){
			child = parent.getLeft();
			if (child.balanceFactor() > 0){
				child = case1(parent);
			}
			else{
				child = case3(parent);
				//update the height of the left child manually
				updateNodeH(child.getLeft());
			}
			if (child.getParent() != null){
				//if the handshake still holds between the previous parent and its parent, rewrite the pointer to the new parent
				if ((parent.getKey()).equals(((child.getParent()).getLeft()).getKey()))
					(child.getParent()).setLeft(child);
				else if ((parent.getKey()).equals(((child.getParent()).getRight()).getKey()))
					(child.getParent()).setRight(child);
			}
		}
		else if (parent.balanceFactor() < -1){
			child = parent.getRight();
			if (child.balanceFactor() > 0){
				child = case4(parent);
				//update the height of the right child manually
				updateNodeH(child.getRight());
			}
			else{
				child = case2(parent);
			}
			if (child.getParent() != null){
				//if the handshake still holds between the previous parent and its parent, rewrite the pointer to the new parent
				if ((parent.getKey()).equals(((child.getParent()).getLeft()).getKey()))
					(child.getParent()).setLeft(child);
				else if ((parent.getKey()).equals(((child.getParent()).getRight()).getKey()))
					(child.getParent()).setRight(child);
			}
		}	
		updateHeight(parent);
		if (child != null) parent = child;
		//stop at the root
		if (parent.getParent() != null){
			//recursive call
			reorderTree(parent.getParent());
		}
		else root = parent;
		
	}
/**
	 * Crawl up the tree from the given node and apply one of the four possible trasformations on each node that is unbalanced
	 * @param parent initially, the AVLTreeNode from which the rebalancing starts
	 */
Crawl up the tree from the given node and apply one of the four possible trasformations on each node that is unbalanced
@param parent initially, the AVLTreeNode from which the rebalancing starts
Crawl up the tree from the given node and apply one of the four possible trasformations on each node that is unbalanced @param parent initially the AVLTreeNode from which the rebalancing starts
private void reorderTree(AVLTreeNode<K,V> parent){
		AVLTreeNode<K,V> child = null;
		if (parent.balanceFactor() > 1){
			child = parent.getLeft();
			if (child.balanceFactor() > 0){
				child = case1(parent);
			}
			else{
				child = case3(parent);
				updateNodeH(child.getLeft());
			}
			if (child.getParent() != null){
				if ((parent.getKey()).equals(((child.getParent()).getLeft()).getKey()))
					(child.getParent()).setLeft(child);
				else if ((parent.getKey()).equals(((child.getParent()).getRight()).getKey()))
					(child.getParent()).setRight(child);
			}
		}
		else if (parent.balanceFactor() < -1){
			child = parent.getRight();
			if (child.balanceFactor() > 0){
				child = case4(parent);
				updateNodeH(child.getRight());
			}
			else{
				child = case2(parent);
			}
			if (child.getParent() != null){
				if ((parent.getKey()).equals(((child.getParent()).getLeft()).getKey()))
					(child.getParent()).setLeft(child);
				else if ((parent.getKey()).equals(((child.getParent()).getRight()).getKey()))
					(child.getParent()).setRight(child);
			}
		}	
		updateHeight(parent);
		if (child != null) parent = child;
		if (parent.getParent() != null){
			reorderTree(parent.getParent());
		}
		else root = parent;
	}
private void reorderTree ( AVLTreeNode < K , V > parent ) { AVLTreeNode < K , V > child = null ; if ( parent . balanceFactor ( ) > 1 ) { child = parent . getLeft ( ) ; if ( child . balanceFactor ( ) > 0 ) { child = case1 ( parent ) ; } else { child = case3 ( parent ) ; updateNodeH ( child . getLeft ( ) ) ; } if ( child . getParent ( ) != null ) { if ( ( parent . getKey ( ) ) . equals ( ( ( child . getParent ( ) ) . getLeft ( ) ) . getKey ( ) ) ) ( child . getParent ( ) ) . setLeft ( child ) ; else if ( ( parent . getKey ( ) ) . equals ( ( ( child . getParent ( ) ) . getRight ( ) ) . getKey ( ) ) ) ( child . getParent ( ) ) . setRight ( child ) ; } } else if ( parent . balanceFactor ( ) < - 1 ) { child = parent . getRight ( ) ; if ( child . balanceFactor ( ) > 0 ) { child = case4 ( parent ) ; updateNodeH ( child . getRight ( ) ) ; } else { child = case2 ( parent ) ; } if ( child . getParent ( ) != null ) { if ( ( parent . getKey ( ) ) . equals ( ( ( child . getParent ( ) ) . getLeft ( ) ) . getKey ( ) ) ) ( child . getParent ( ) ) . setLeft ( child ) ; else if ( ( parent . getKey ( ) ) . equals ( ( ( child . getParent ( ) ) . getRight ( ) ) . getKey ( ) ) ) ( child . getParent ( ) ) . setRight ( child ) ; } } updateHeight ( parent ) ; if ( child != null ) parent = child ; if ( parent . getParent ( ) != null ) { reorderTree ( parent . getParent ( ) ) ; } else root = parent ; }
Crawl up the tree from the given node and apply one of the four possible trasformations on each node that is unbalanced
 @param parent initially, the AVLTreeNode from which the rebalancing starts
Crawl up the tree from the given node and apply one of the four possible trasformations on each node that is unbalanced @param parent initially the AVLTreeNode from which the rebalancing starts
//Find the unbalanced grandchild by finding the unbalanced child first. With this method, we get three nodes and four other subtrees. From here, depending on the alignment of the three nodes, four different cases can occur //update the height of the left child manually //if the handshake still holds between the previous parent and its parent, rewrite the pointer to the new parent //update the height of the right child manually //if the handshake still holds between the previous parent and its parent, rewrite the pointer to the new parent //stop at the root //recursive call