mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-01 00:41:09 +00:00
a2236cfb97
* Improved Formatting of basic_maths.py - Added docstrings. - Improved whitespace formatting. - Renamed functions to match snake_case. * Improved Formatting of factorial_python.py - Added docstrings. - Improved whitespace formatting. - Renamed constants to match UPPER_CASE. * Improved Formatting of factorial_recursive.py - Improved whitespace formatting to meet PyLint standards. * Improved Code to Conform to PyLint - Renamed `max` to `max_num` to avoid redefining built-in 'max' [pylint] - Removed unnecessary parens after 'while' keyword [pylint] * Improved Formatting of factorial_recursive.py - Added docstrings. - Improved whitespace formatting.
21 lines
526 B
Python
21 lines
526 B
Python
"""Pancake Sort Algorithm."""
|
|
# Only can reverse array from 0 to i
|
|
|
|
|
|
def pancake_sort(arr):
|
|
"""Sort Array with Pancake Sort."""
|
|
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]))
|