# -*- coding:utf-8 -*-


import numpy as np


class MaxHeap(object):


    def __init__(self, sz, data):
        self.sz  = sz
        self.heap = [0] * (sz + 1)
        self.cnt = len(data)
        self.heap[1: self.cnt + 1] = data
        self.build_heap()
        
    def build_heap(self):
        last_non_leaf = self.cnt // 2
        for i in range(last_non_leaf, 0, -1):
            self.heapify(self.heap, self.sz, i)

    def heapify(self, heap, sz, ele_ind):
        while True:
            max_pos = ele_ind
            if  2 * ele_ind < sz and heap[ele_ind] < heap[2 * ele_ind]:
                max_pos = 2 * ele_ind
            if (2 * ele_ind + 1) < sz and heap[max_pos] < heap[2 * ele_ind + 1]:
                max_pos = 2 * ele_ind + 1
            if max_pos == ele_ind:
                break
            heap[ele_ind], heap[max_pos] = heap[max_pos], heap[ele_ind]
            ele_ind = max_pos
    
            
                
    

if __name__ == '__main__':
    data = np.random.randint(0, 100, 10)
    print(data)
    heap = MaxHeap(100, data)
    print(heap.heap)

@@ -412,18 +412,19 @@
 p, self.
-sz
+cnt
 , i)%0A%0A  
@@ -528,17 +528,17 @@
      if 
- 
+(
 2 * ele_
@@ -542,19 +542,21 @@
 le_ind %3C
+=
  sz
+)
  and hea
@@ -659,16 +659,17 @@
 d + 1) %3C
+=
  sz and 
@@ -805,16 +805,17 @@
    break
+ 
 %0A       
@@ -909,33 +909,666 @@
 max_pos%0A
+%0A
     
-%0A            
+def remove_max(self):%0A        if self.cnt == 0 :%0A            return  - 1%0A        self.heap%5B1%5D = self.heap%5Bself.cnt%5D%0A        self.heap%5Bself.cnt%5D = 0%0A        self.cnt -= 1%0A        self.heapify(self.heap, self.cnt, 1)%0A        return 0%0A        %0A    def insert(self, item):%0A        if self.cnt %3E= self.sz:%0A            return False%0A        self.cnt += 1%0A        self.heap%5Bself.cnt%5D = item%0A        i = self.cnt%0A        while True:%0A            if i // 2 %3E 0 and self.heap%5Bi%5D %3E self.heap%5Bi // 2%5D:%0A                self.heap%5Bi%5D, self.heap%5Bi // 2%5D = self.heap%5Bi // 2%5D , self.heap%5Bi%5D%0A                i = i // 2%0A            else:%0A                return True%0A%0A
 %0A       
@@ -1686,18 +1686,17 @@
 MaxHeap(
-10
+2
 0, data)
@@ -1717,8 +1717,95 @@
 p.heap)%0A
+    heap.remove_max()%0A    print(heap.heap)%0A    heap.insert(1000)%0A    print(heap.heap)%0A%0A

Add remove_max and insert method for heap