sorts.heap_sort

A pure Python implementation of the heap sort algorithm.

Attributes

user_input

Functions

heap_sort(→ list[int])

A pure Python implementation of the heap sort algorithm

heapify(→ None)

Module Contents

sorts.heap_sort.heap_sort(unsorted: list[int]) list[int]

A pure Python implementation of the heap sort algorithm

Parameters:

collection – a mutable ordered collection of heterogeneous comparable items

Returns:

the same collection ordered by ascending

Examples: >>> heap_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> heap_sort([]) [] >>> heap_sort([-2, -5, -45]) [-45, -5, -2] >>> heap_sort([3, 7, 9, 28, 123, -5, 8, -30, -200, 0, 4]) [-200, -30, -5, 0, 3, 4, 7, 8, 9, 28, 123]

sorts.heap_sort.heapify(unsorted: list[int], index: int, heap_size: int) None
Parameters:
  • unsorted – unsorted list containing integers numbers

  • index – index

  • heap_size – size of the heap

Returns:

None

>>> unsorted = [1, 4, 3, 5, 2]
>>> heapify(unsorted, 0, len(unsorted))
>>> unsorted
[4, 5, 3, 1, 2]
>>> heapify(unsorted, 0, len(unsorted))
>>> unsorted
[5, 4, 3, 1, 2]
sorts.heap_sort.user_input