(arr, end)
Max heapify helper for max_heap_sort
Max heapify helper for max_heap_sort
Max heapify helper for max_heap_sort
def max_heapify(arr, end):
    """ Max heapify helper for max_heap_sort
    """
    last_parent = int((end - 1) / 2)

    # Iterate from last parent to first
    for parent in range(last_parent, -1, -1):
        current_parent = parent

        # Iterate from current_parent to last_parent
        while current_parent <= last_parent:
            # Find greatest child of current_parent
            child = 2 * current_parent + 1
            if child + 1 <= end and arr[child] < arr[child + 1]:
                child = child + 1

            # Swap if child is greater than parent
            if arr[child] > arr[current_parent]:
                temp = arr[current_parent]
                arr[current_parent] = arr[child]
                arr[child] = temp

                current_parent = child
            # If no swap occured, no need to keep iterating
            else:
                break
def max_heapify ( arr , end ) : last_parent = int ( ( end - 1 ) / 2 ) # Iterate from last parent to first for parent in range ( last_parent , - 1 , - 1 ) : current_parent = parent # Iterate from current_parent to last_parent while current_parent <= last_parent : # Find greatest child of current_parent child = 2 * current_parent + 1 if child + 1 <= end and arr [ child ] < arr [ child + 1 ] : child = child + 1 # Swap if child is greater than parent if arr [ child ] > arr [ current_parent ] : temp = arr [ current_parent ] arr [ current_parent ] = arr [ child ] arr [ child ] = temp current_parent = child # If no swap occured, no need to keep iterating else : break