MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / pancakesort

Function pancakesort

sorts/pancake_sort.py:4–14  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

2# Only can reverse array from 0 to i
3
4def pancakesort(arr):
5 cur = len(arr)
6 while cur > 1:
7 # Find the maximum number in arr
8 mi = arr.index(max(arr[0:cur]))
9 # Reverse from 0 to mi
10 arr = arr[mi::-1] + arr[mi+1:len(arr)]
11 # Reverse whole list
12 arr = arr[cur-1::-1] + arr[cur:len(arr)]
13 cur -= 1
14 return arr
15
16print(pancakesort([0,10,15,3,2,9,14,13]))

Callers 1

pancake_sort.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected