budget/src/main/java/budget/backend/structures/AVLSearchTree.java
private AVLTreeNode<K,V> findPlace(K key, AVLTreeNode<K,V> from){
		//avoid null-pointer errors
		if (from.isLeaf()){
			//three cases are likely to occur, left is external, right is external, both are external.
			if (key.compareTo(from.getKey()) < 0){
				if (from.getLeft() == empty){
					AVLTreeNode<K,V> ret = new AVLTreeNode<K,V>(from, key);
					from.setLeft(ret);
					return ret;
				}
				else {
					return findPlace(key, from.getLeft());
				}
			}
			else if (key.compareTo(from.getKey()) > 0){
				if (from.getRight() == empty){
					AVLTreeNode<K,V> ret = new AVLTreeNode<K,V>(from, key);
					from.setRight(ret);
					return ret;
				}
				else 
					return findPlace(key, from.getRight());
			} else return empty; //equality is not permitted between keys
		}
		//find the next node in the binary search
		else {
			if (key.compareTo(from.getKey()) < 0){
				return findPlace(key, from.getLeft());
			} else if (key.compareTo(from.getKey()) > 0) return findPlace(key, from.getRight());
			else return empty; //equality is not permitted between keys
		}

	}
/**
	 * Recursively find a path to a node on which the BinarySearch properties hold, and end on a node, which has at least one empty leaf. Initialise a new AVLTreeNode and set its parent. Set the node as the child of the parent
	 * @param key a Comparable instance
	 * @param from an AVLTreeNode object
	 * @return the new AVLTreeNode
	 */
Recursively find a path to a node on which the BinarySearch properties hold, and end on a node, which has at least one empty leaf. Initialise a new AVLTreeNode and set its parent. Set the node as the child of the parent
@param key a Comparable instance
@param from an AVLTreeNode object
@return the new AVLTreeNode
Recursively find a path to a node on which the BinarySearch properties hold and end on a node which has at least one empty leaf . Initialise a new AVLTreeNode and set its parent . Set the node as the child of the parent @param key a Comparable instance @param from an AVLTreeNode object @return the new AVLTreeNode
private AVLTreeNode<K,V> findPlace(K key, AVLTreeNode<K,V> from){
		if (from.isLeaf()){
			if (key.compareTo(from.getKey()) < 0){
				if (from.getLeft() == empty){
					AVLTreeNode<K,V> ret = new AVLTreeNode<K,V>(from, key);
					from.setLeft(ret);
					return ret;
				}
				else {
					return findPlace(key, from.getLeft());
				}
			}
			else if (key.compareTo(from.getKey()) > 0){
				if (from.getRight() == empty){
					AVLTreeNode<K,V> ret = new AVLTreeNode<K,V>(from, key);
					from.setRight(ret);
					return ret;
				}
				else 
					return findPlace(key, from.getRight());
			} else return empty; 
		}
		else {
			if (key.compareTo(from.getKey()) < 0){
				return findPlace(key, from.getLeft());
			} else if (key.compareTo(from.getKey()) > 0) return findPlace(key, from.getRight());
			else return empty; 
		}
	}
private AVLTreeNode < K , V > findPlace ( K key , AVLTreeNode < K , V > from ) { if ( from . isLeaf ( ) ) { if ( key . compareTo ( from . getKey ( ) ) < 0 ) { if ( from . getLeft ( ) == empty ) { AVLTreeNode < K , V > ret = new AVLTreeNode < K , V > ( from , key ) ; from . setLeft ( ret ) ; return ret ; } else { return findPlace ( key , from . getLeft ( ) ) ; } } else if ( key . compareTo ( from . getKey ( ) ) > 0 ) { if ( from . getRight ( ) == empty ) { AVLTreeNode < K , V > ret = new AVLTreeNode < K , V > ( from , key ) ; from . setRight ( ret ) ; return ret ; } else return findPlace ( key , from . getRight ( ) ) ; } else return empty ; } else { if ( key . compareTo ( from . getKey ( ) ) < 0 ) { return findPlace ( key , from . getLeft ( ) ) ; } else if ( key . compareTo ( from . getKey ( ) ) > 0 ) return findPlace ( key , from . getRight ( ) ) ; else return empty ; } }
Recursively find a path to a node on which the BinarySearch properties hold, and end on a node, which has at least one empty leaf.
Recursively find a path to a node on which the BinarySearch properties hold and end on a node which has at least one empty leaf .
//avoid null-pointer errors //three cases are likely to occur, left is external, right is external, both are external. //equality is not permitted between keys //find the next node in the binary search //equality is not permitted between keys