def max_heapify(arr, end, simulation, iteration):
last_parent = (end - <NUM_LIT:1>) // <NUM_LIT:2><EOL>for parent in range(last_parent, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>current_parent = parent<EOL>while current_parent <= last_parent:<EOL><INDENT>child = <NUM_LIT:2> * current_parent + <NUM_LIT:1><EOL>if child + <NUM_LIT:1> <= end and arr[child] < arr[child + <NUM_LIT:1>]:<EOL><INDENT>child = child + <NUM_LIT:1><EOL><DEDENT>if arr[child] > arr[current_parent]:<EOL><INDENT>arr[current_parent], arr[child] = arr[child], arr[current_parent]<EOL>current_parent = child<EOL>if simulation:<EOL><INDENT>iteration = iteration + <NUM_LIT:1><EOL>print("<STR_LIT>",iteration,"<STR_LIT::>",*arr)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>arr[<NUM_LIT:0>], arr[end] = arr[end], arr[<NUM_LIT:0>]<EOL>return iteration<EOL>
Max heapify helper for max_heap_sort