Skip to content

Instantly share code, notes, and snippets.

@tiwarinaman
Created August 30, 2020 09:25
Show Gist options
  • Select an option

  • Save tiwarinaman/306b01d18a782d71b907a509ac99daee to your computer and use it in GitHub Desktop.

Select an option

Save tiwarinaman/306b01d18a782d71b907a509ac99daee to your computer and use it in GitHub Desktop.
Max Heap
data = [0,85,75,60,30,35,45]
def maxHeapInsert(item):
pos = len(data)
data.insert(pos,item)
print('After inserting the element in the heap')
print(data)
if pos!=0:
while data[int(pos/2) <= item and int(pos/2) >=1]:
data[pos] = data[int(pos/2)]
data[int(pos/2)] = item
print(data)
pos = int(pos/2)
print('Heap format in array ')
print(data)
maxHeapInsert(92)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment