• Inserts a new element into the splay tree

    Follows the standard splay tree insertion algorithm:

    1. If tree is empty, create a new single-node tree
    2. Otherwise, perform standard BST insertion
    3. Splay the newly inserted element to the root

    Note: If the element already exists, it will be splayed to root but no duplicate is added. This maintains the BST property while ensuring the accessed element becomes the root.

    Parameters

    • value: any

      the value to insert

    • tree: SplayTree<any>

      the tree to insert into

    Returns SplayTree<any>

    the new tree with the inserted value splayed to root