budget/src/main/java/budget/backend/structures/AVLSearchTree.java
private AVLTreeNode<K,V> removeLeaf(AVLTreeNode<K,V> node){
			if (((node.getLeft()).equals(empty)) && ((node.getRight()).equals(empty))){
				//both are empty, delete the node
				if (node.isLeft())
					(node.getParent()).setLeft(empty);
				else 
					(node.getParent()).setRight(empty);
		
			}
			else {
				AVLTreeNode<K,V> nonLeaf = null;
				//there is one that is not empty, put it in the place of node. Ensure the handshake between it and its parent
				if ((node.getLeft()).equals(empty)){
					nonLeaf = node.getRight();
				}
				else if ((node.getRight()).equals(empty)){
					nonLeaf = node.getLeft();
				}
				if (nonLeaf != null){
					if (node.isLeft())
						(node.getParent()).setLeft(nonLeaf);
					else 
						(node.getParent()).setRight(nonLeaf);
					nonLeaf.setParent(node.getParent());
				}
			}
			//refresh the heights of the subtree from which the removal happened
			updateHeight(node);
			return node;
	}
/**
	 * Remove an external node from the tree. if there is at most one, non-empty leaf, put it in its place
	 */
Remove an external node from the tree. if there is at most one, non-empty leaf, put it in its place
Remove an external node from the tree . if there is at most one non - empty leaf put it in its place
private AVLTreeNode<K,V> removeLeaf(AVLTreeNode<K,V> node){
			if (((node.getLeft()).equals(empty)) && ((node.getRight()).equals(empty))){
				if (node.isLeft())
					(node.getParent()).setLeft(empty);
				else 
					(node.getParent()).setRight(empty);
			}
			else {
				AVLTreeNode<K,V> nonLeaf = null;
				if ((node.getLeft()).equals(empty)){
					nonLeaf = node.getRight();
				}
				else if ((node.getRight()).equals(empty)){
					nonLeaf = node.getLeft();
				}
				if (nonLeaf != null){
					if (node.isLeft())
						(node.getParent()).setLeft(nonLeaf);
					else 
						(node.getParent()).setRight(nonLeaf);
					nonLeaf.setParent(node.getParent());
				}
			}
			updateHeight(node);
			return node;
	}
private AVLTreeNode < K , V > removeLeaf ( AVLTreeNode < K , V > node ) { if ( ( ( node . getLeft ( ) ) . equals ( empty ) ) && ( ( node . getRight ( ) ) . equals ( empty ) ) ) { if ( node . isLeft ( ) ) ( node . getParent ( ) ) . setLeft ( empty ) ; else ( node . getParent ( ) ) . setRight ( empty ) ; } else { AVLTreeNode < K , V > nonLeaf = null ; if ( ( node . getLeft ( ) ) . equals ( empty ) ) { nonLeaf = node . getRight ( ) ; } else if ( ( node . getRight ( ) ) . equals ( empty ) ) { nonLeaf = node . getLeft ( ) ; } if ( nonLeaf != null ) { if ( node . isLeft ( ) ) ( node . getParent ( ) ) . setLeft ( nonLeaf ) ; else ( node . getParent ( ) ) . setRight ( nonLeaf ) ; nonLeaf . setParent ( node . getParent ( ) ) ; } } updateHeight ( node ) ; return node ; }
Remove an external node from the tree.
Remove an external node from the tree .
//both are empty, delete the node //there is one that is not empty, put it in the place of node. Ensure the handshake between it and its parent //refresh the heights of the subtree from which the removal happened