• Splays a tree to move the element with the given value to the root

    This is the core operation of splay trees. It uses three types of rotations based on the standard splay tree terminology:

    • Zig/Zag: Single rotation when target's parent is root (zig=left child, zag=right child)
    • Zig-zig/Zag-zag: Double rotation when target and parent are both left or both right children
    • Zig-zag/Zag-zig: Double rotation when target and parent are on opposite sides

    Parameters

    • target: any

      the value to splay to the root

    • tree: SplayTree<any>

      the tree to splay

    Returns SplayTree<any>

    the tree with target at the root (or closest node if target not found)