mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 01:00:15 +00:00
Update heap_sort.py
This commit is contained in:
parent
ba37aef219
commit
bb70803c9e
|
@ -7,7 +7,7 @@ or
|
||||||
python3 -m doctest -v heap_sort.py
|
python3 -m doctest -v heap_sort.py
|
||||||
|
|
||||||
For manual testing run:
|
For manual testing run:
|
||||||
python insertion_sort.py
|
python heap_sort.py
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
@ -46,7 +46,7 @@ def heap_sort(unsorted):
|
||||||
n = len(unsorted)
|
n = len(unsorted)
|
||||||
for i in range(n//2 - 1, -1, -1):
|
for i in range(n//2 - 1, -1, -1):
|
||||||
heapify(unsorted, i, n)
|
heapify(unsorted, i, n)
|
||||||
for i in range(n - 1, -1, -1):
|
for i in range(n - 1, 0, -1):
|
||||||
unsorted[0], unsorted[i] = unsorted[i], unsorted[0]
|
unsorted[0], unsorted[i] = unsorted[i], unsorted[0]
|
||||||
heapify(unsorted, 0, i)
|
heapify(unsorted, 0, i)
|
||||||
return unsorted
|
return unsorted
|
||||||
|
|
Loading…
Reference in New Issue
Block a user