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

Function heapSort

Sorting Algorithms/Heap sort.py:29–40  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

27
28# The main function to sort an array of given size
29def heapSort(arr):
30 n = len(arr)
31
32 # Build a maxheap.
33 # Since last parent will be at ((n//2)-1) we can start at that location.
34 for i in range(n // 2 - 1, -1, -1):
35 heapify(arr, n, i)
36
37 # One by one extract elements
38 for i in range(n - 1, 0, -1):
39 arr[i], arr[0] = arr[0], arr[i] # swap
40 heapify(arr, i, 0)
41
42
43# Driver code to test above

Callers 1

Heap sort.pyFile · 0.70

Calls 1

heapifyFunction · 0.70

Tested by

no test coverage detected