defpop(self): top = self.__values[0] self.__swap(0, len(self.__values) - 1) self.__values.pop() i = 0 whileTrue: left = 2 * i + 1 right = 2 * i + 2 max_ = i if left < len(self.__values) and self.__values[left] < self.__values[max_]: max_ = left if right < len(self.__values) and self.__values[right] < self.__values[max_]: max_ = right if max_ == i: break self.__swap(i, max_) i = max_ return top
defisEmpty(self): returnlen(self.__values) == 0
def__len__(self): returnlen(self.__values)
@staticmethod deffromList(data_list: list): heap = MinHeap() for i in data_list: heap.push(i) return heap