mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +08:00
psf/black code formatting (#1277)
This commit is contained in:

committed by
Christian Clauss

parent
07f04a2e55
commit
9eac17a408
@ -1,4 +1,4 @@
|
||||
'''
|
||||
"""
|
||||
This is a pure python implementation of the heap sort algorithm.
|
||||
|
||||
For doctests run following command:
|
||||
@ -8,7 +8,8 @@ python3 -m doctest -v heap_sort.py
|
||||
|
||||
For manual testing run:
|
||||
python heap_sort.py
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
def heapify(unsorted, index, heap_size):
|
||||
largest = index
|
||||
@ -26,7 +27,7 @@ def heapify(unsorted, index, heap_size):
|
||||
|
||||
|
||||
def heap_sort(unsorted):
|
||||
'''
|
||||
"""
|
||||
Pure implementation of the heap sort algorithm in Python
|
||||
:param collection: some mutable ordered collection with heterogeneous
|
||||
comparable items inside
|
||||
@ -41,7 +42,7 @@ def heap_sort(unsorted):
|
||||
|
||||
>>> heap_sort([-2, -5, -45])
|
||||
[-45, -5, -2]
|
||||
'''
|
||||
"""
|
||||
n = len(unsorted)
|
||||
for i in range(n // 2 - 1, -1, -1):
|
||||
heapify(unsorted, i, n)
|
||||
@ -50,7 +51,8 @@ def heap_sort(unsorted):
|
||||
heapify(unsorted, 0, i)
|
||||
return unsorted
|
||||
|
||||
if __name__ == '__main__':
|
||||
user_input = input('Enter numbers separated by a comma:\n').strip()
|
||||
unsorted = [int(item) for item in user_input.split(',')]
|
||||
|
||||
if __name__ == "__main__":
|
||||
user_input = input("Enter numbers separated by a comma:\n").strip()
|
||||
unsorted = [int(item) for item in user_input.split(",")]
|
||||
print(heap_sort(unsorted))
|
||||
|
Reference in New Issue
Block a user