budget/src/main/java/budget/backend/structures/BinaryTreeHeap.java
private void findNext(){
		BinaryTreeNode<K,V> ptr = last;

		//find a left child, or the root
		while ((ptr.getParent() != null) && (!(ptr.equals((ptr.getParent()).getLeft())))){
			ptr = ptr.getParent();
		}

		//find the right child of the parent, if there is a parent
		if (ptr.getParent() != null){
			if ((ptr.getParent()).getRight() != null)
		  	ptr = (ptr.getParent()).getRight();
			else {
				ptr = new BinaryTreeNode<K,V>(ptr.getParent(), null);
				(ptr.getParent()).setRight(ptr);
			}
		}

		if (ptr.getKey() != null){
			//find the leftmost leaf in the subtree
			while (!(ptr.isLeaf())){
				ptr = ptr.getLeft();
			}

			//return the left node if empty, return the right node otherwise.
			last = new BinaryTreeNode<K,V>(ptr, null);
			if (ptr.getLeft() == null){
				ptr.setLeft(last);
			}
			else {
				ptr.setRight(last);
			}
		} else last = ptr;

	}
/**
	 * Find the next last node of the tree. It can always be found by going up the tree until a left child or the root is found. If there is any, get the right child of the parent, then go down left until a leaf is found. A leaf has at least one empty child. Insert a new node that has the leaf as parent
	 */
Find the next last node of the tree. It can always be found by going up the tree until a left child or the root is found. If there is any, get the right child of the parent, then go down left until a leaf is found. A leaf has at least one empty child. Insert a new node that has the leaf as parent
Find the next last node of the tree . It can always be found by going up the tree until a left child or the root is found . If there is any get the right child of the parent then go down left until a leaf is found . A leaf has at least one empty child . Insert a new node that has the leaf as parent
private void findNext(){
		BinaryTreeNode<K,V> ptr = last;
		while ((ptr.getParent() != null) && (!(ptr.equals((ptr.getParent()).getLeft())))){
			ptr = ptr.getParent();
		}
		if (ptr.getParent() != null){
			if ((ptr.getParent()).getRight() != null)
		  	ptr = (ptr.getParent()).getRight();
			else {
				ptr = new BinaryTreeNode<K,V>(ptr.getParent(), null);
				(ptr.getParent()).setRight(ptr);
			}
		}
		if (ptr.getKey() != null){
			while (!(ptr.isLeaf())){
				ptr = ptr.getLeft();
			}
			last = new BinaryTreeNode<K,V>(ptr, null);
			if (ptr.getLeft() == null){
				ptr.setLeft(last);
			}
			else {
				ptr.setRight(last);
			}
		} else last = ptr;
	}
private void findNext ( ) { BinaryTreeNode < K , V > ptr = last ; while ( ( ptr . getParent ( ) != null ) && ( ! ( ptr . equals ( ( ptr . getParent ( ) ) . getLeft ( ) ) ) ) ) { ptr = ptr . getParent ( ) ; } if ( ptr . getParent ( ) != null ) { if ( ( ptr . getParent ( ) ) . getRight ( ) != null ) ptr = ( ptr . getParent ( ) ) . getRight ( ) ; else { ptr = new BinaryTreeNode < K , V > ( ptr . getParent ( ) , null ) ; ( ptr . getParent ( ) ) . setRight ( ptr ) ; } } if ( ptr . getKey ( ) != null ) { while ( ! ( ptr . isLeaf ( ) ) ) { ptr = ptr . getLeft ( ) ; } last = new BinaryTreeNode < K , V > ( ptr , null ) ; if ( ptr . getLeft ( ) == null ) { ptr . setLeft ( last ) ; } else { ptr . setRight ( last ) ; } } else last = ptr ; }
Find the next last node of the tree.
Find the next last node of the tree .
//find a left child, or the root //find the right child of the parent, if there is a parent //find the leftmost leaf in the subtree //return the left node if empty, return the right node otherwise.