1-Relational Database/1-Relational DB Concepts/B-Tree & B+ Tree/java/BTreeBase.java
/**
     * Private helper method to insert the given key-record mapping to the given
     * subtree recursively.
     * @param curr current node
     * @param key key to insert
     * @param recordAddress record address with the key
     * @param path path along which to find the leaf
     * @param pastInsertPositions insert positions along path
     */
Private helper method to insert the given key-record mapping to the given
subtree recursively.
Private helper method to insert the given key - record mapping to the given subtree recursively .
private void insertHelper(Node curr, int key, String recordAddress, Stack<Node> path,
            Stack<Integer> pastInsertPositions) {
        int pos = curr.findInsertPos(key);
        if (pos >= 0) { 
            return;
        }
        int insertPos = -pos - 1;
        if (curr.isLeaf()) { 
            curr.insertEntry(insertPos, new IndexEntry(key, recordAddress), null, null);
            if (curr.isOverflowed()) {
                percolateUp(curr, path, pastInsertPositions);
            }
            return;
        }
        path.push(curr);
        pastInsertPositions.push(insertPos);
        insertHelper(curr.getChild(insertPos), key, recordAddress, path, pastInsertPositions);
    }
private void insertHelper ( Node curr , int key , String recordAddress , Stack < Node > path , Stack < Integer > pastInsertPositions ) { int pos = curr . findInsertPos ( key ) ; if ( pos >= 0 ) { return ; } int insertPos = - pos - 1 ; if ( curr . isLeaf ( ) ) { curr . insertEntry ( insertPos , new IndexEntry ( key , recordAddress ) , null , null ) ; if ( curr . isOverflowed ( ) ) { percolateUp ( curr , path , pastInsertPositions ) ; } return ; } path . push ( curr ) ; pastInsertPositions . push ( insertPos ) ; insertHelper ( curr . getChild ( insertPos ) , key , recordAddress , path , pastInsertPositions ) ; }
Private helper method to insert the given key-record mapping to the given
 subtree recursively.
Private helper method to insert the given key - record mapping to the given subtree recursively .
// Found it // No duplicate key allowed to be inserted // Leaf // Insert into the leaf node first, and if the leaf node itself is overflowed, percolate up // Non-leaf // Go to the appropriate child