budget/src/main/java/budget/backend/structures/BinaryTreeHeap.java
private void downHeap(BinaryTreeNode<K,V> subTree){
		//Avoiding compareTo errors
		if (subTree.isLeaf()){
			if ((subTree.getLeft() != null) && ((subTree.getKey()).compareTo((subTree.getLeft()).getKey()) > 0))
				sw(subTree, subTree.getLeft());
			else if ((subTree.getRight() != null) && ((subTree.getKey()).compareTo((subTree.getRight()).getKey()) > 0))
				sw(subTree, subTree.getRight());
		}
		//if subTree is not a leaf, switch with the smaller child (if any) and recuresively call downHeap with the child
		else {
			int which = ((subTree.getLeft()).getKey()).compareTo((subTree.getRight()).getKey());
			if ((which<0) && ((subTree.getKey()).compareTo((subTree.getLeft()).getKey()) > 0)){
				sw(subTree, subTree.getLeft());
				downHeap(subTree.getLeft());
			}
			else if ((subTree.getKey()).compareTo((subTree.getRight()).getKey()) > 0){
				sw(subTree, subTree.getRight());
				downHeap(subTree.getRight());
			}
		}
	}
/**
	 * Implementation of downheap from the root. Switch the key of the smaller child and the parent, while the parent is bigger than or equal to the child
	 * @param subTree the root by default, then all the subtrees, in which a switch has been performed
	 */
Implementation of downheap from the root. Switch the key of the smaller child and the parent, while the parent is bigger than or equal to the child
@param subTree the root by default, then all the subtrees, in which a switch has been performed
Implementation of downheap from the root . Switch the key of the smaller child and the parent while the parent is bigger than or equal to the child @param subTree the root by default then all the subtrees in which a switch has been performed
private void downHeap(BinaryTreeNode<K,V> subTree){
		if (subTree.isLeaf()){
			if ((subTree.getLeft() != null) && ((subTree.getKey()).compareTo((subTree.getLeft()).getKey()) > 0))
				sw(subTree, subTree.getLeft());
			else if ((subTree.getRight() != null) && ((subTree.getKey()).compareTo((subTree.getRight()).getKey()) > 0))
				sw(subTree, subTree.getRight());
		}
		else {
			int which = ((subTree.getLeft()).getKey()).compareTo((subTree.getRight()).getKey());
			if ((which<0) && ((subTree.getKey()).compareTo((subTree.getLeft()).getKey()) > 0)){
				sw(subTree, subTree.getLeft());
				downHeap(subTree.getLeft());
			}
			else if ((subTree.getKey()).compareTo((subTree.getRight()).getKey()) > 0){
				sw(subTree, subTree.getRight());
				downHeap(subTree.getRight());
			}
		}
	}
private void downHeap ( BinaryTreeNode < K , V > subTree ) { if ( subTree . isLeaf ( ) ) { if ( ( subTree . getLeft ( ) != null ) && ( ( subTree . getKey ( ) ) . compareTo ( ( subTree . getLeft ( ) ) . getKey ( ) ) > 0 ) ) sw ( subTree , subTree . getLeft ( ) ) ; else if ( ( subTree . getRight ( ) != null ) && ( ( subTree . getKey ( ) ) . compareTo ( ( subTree . getRight ( ) ) . getKey ( ) ) > 0 ) ) sw ( subTree , subTree . getRight ( ) ) ; } else { int which = ( ( subTree . getLeft ( ) ) . getKey ( ) ) . compareTo ( ( subTree . getRight ( ) ) . getKey ( ) ) ; if ( ( which < 0 ) && ( ( subTree . getKey ( ) ) . compareTo ( ( subTree . getLeft ( ) ) . getKey ( ) ) > 0 ) ) { sw ( subTree , subTree . getLeft ( ) ) ; downHeap ( subTree . getLeft ( ) ) ; } else if ( ( subTree . getKey ( ) ) . compareTo ( ( subTree . getRight ( ) ) . getKey ( ) ) > 0 ) { sw ( subTree , subTree . getRight ( ) ) ; downHeap ( subTree . getRight ( ) ) ; } } }
Implementation of downheap from the root.
Implementation of downheap from the root .
//Avoiding compareTo errors //if subTree is not a leaf, switch with the smaller child (if any) and recuresively call downHeap with the child