```python
def pancake_sort(nums):
    def flip(arr, k):
        """Reverses the prefix of the array of length k."""
        i = 0
        while i < k / 2:
            arr[i], arr[k - 1 - i] = arr[k - 1 - i], arr[i]
            i += 1

    n = len(nums)
    for current_size in range(n, 1, -1):
        # Find the index of the maximum element in the unsorted sub-array
        # The unsorted sub-array is nums[0:current_size]
        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 position
        if max_index != current_size - 1:
            # 1. Bring the maximum element to the front (if it's not already there)
            if max_index != 0:
                flip(nums, max_index + 1)
            
            # 2. Flip the entire unsorted part to move the maximum element to its correct place
            flip(nums, current_size)
```