Element Insertion Process in a Sorted Stack

This animation demonstrates how the insertSorted function works when inserting a new element (31) into a partially sorted stack [3, 23, 34, 92, 98]. The process involves temporarily removing elements that are larger than the new element, inserting the new element, and then putting back the removed elements.

Original Stack
Temporary Storage
Result Stack
Starting with a partially sorted stack [3, 23, 34, 92, 98]. We want to insert 31 in the correct position.