MCPcopy Create free account
hub / github.com/geekcomputers/Python / heap_sort

Function heap_sort

Sorting Algorithms/heap_sort.py:23–37  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

21
22
23def heap_sort(nums):
24 n = len(nums)
25
26 # Create a Max Heap from the list
27 # The 2nd argument of range means we stop at the element before -1 i.e.
28 # the first element of the list.
29 # The 3rd argument of range means we iterate backwards, reducing the count
30 # of i by 1
31 for i in range(n, -1, -1):
32 heapify(nums, n, i)
33
34 # Move the root of the max heap to the end of
35 for i in range(n - 1, 0, -1):
36 nums[i], nums[0] = nums[0], nums[i]
37 heapify(nums, i, 0)
38
39
40# Verify it works

Callers 1

heap_sort.pyFile · 0.85

Calls 1

heapifyFunction · 0.70

Tested by

no test coverage detected