Update heap_sort.py

This commit is contained in:
yyeltsyn 2016-09-02 13:59:46 +03:00 committed by GitHub
parent ba37aef219
commit bb70803c9e

View File

@ -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