mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-28 07:21:07 +00:00
02c0daf9e5
* Adding variable to fade out ambiguity * More readability on merge sorting algorithm * Updating merge_sort_fastest description and explaining why * Adding tests file with imports * Standardazing filenames and function names * Adding test cases and test functions * Adding test loop * Putting 'user oriented code' inside main condition for having valid imports * Fixing condition * Updating tests: adding cases and todo list * Refactoring first euler problem's first solution
18 lines
471 B
Python
18 lines
471 B
Python
# Pancake sort algorithm
|
|
# Only can reverse array from 0 to i
|
|
|
|
def pancake_sort(arr):
|
|
cur = len(arr)
|
|
while cur > 1:
|
|
# Find the maximum number in arr
|
|
mi = arr.index(max(arr[0:cur]))
|
|
# Reverse from 0 to mi
|
|
arr = arr[mi::-1] + arr[mi+1:len(arr)]
|
|
# Reverse whole list
|
|
arr = arr[cur-1::-1] + arr[cur:len(arr)]
|
|
cur -= 1
|
|
return arr
|
|
|
|
if __name__ == '__main__':
|
|
print(pancake_sort([0,10,15,3,2,9,14,13]))
|