```python
def pancake_sort(nums):
    """
    Sorts a list of elements using the pancake sort algorithm.
    """
    def flip(k):
        """Reverses the prefix of the list `nums` of length `k`."""
        # Use slicing to reverse the first k elements of the list.
        # This modifies the list in-place.
        nums[:k] = nums[:k][::-1]

    n = len(nums)
    # Iterate from the full list size down to 2.
    # In each iteration, we place the largest element of the unsorted
    # part at its correct final position.
    for current_size in range(n, 1, -1):
        # Find the index of the maximum element in the unsorted part,
        # which is the prefix nums[0...current_size-1].
        max_index = 0
        for i in range(1, current_size):
            if nums[i] > nums[max_index]:
                max_index = i

        # If the maximum element is not already in its correct sorted position.
        if max_index != current_size - 1:
            # First flip: bring the maximum element to the front (index 0).
            # If max_index is 0, this flip(1) is a no-op, which is correct.
            flip(max_index + 1)
            
            # Second flip: move the maximum element (now at the front) to its
            # correct sorted position at the end of the unsorted part.
            flip(current_size)
```