heapify

Run Settings
LanguagePython
Language Version
Run Command
arr = [0] + list(map(int,input().split())) n = len(arr) - 1 def max_heapify(arr,i,n): temp = arr[i] j = 2*i while (j<=n): if j < n and arr[j+1] > arr[j]: j += 1 if temp > arr[j] : break elif arr[j] >= temp : arr[j//2] = arr[j] j = j*2 arr[j//2] = temp print(arr,n//2,n) for i in range(n//2,0,-1): max_heapify(arr,i,n) print(arr)
Editor Settings
Theme
Key bindings
Full width
Lines