def _sink(self, k): while 2 * k <= self.size: j = 2 * k if j < self.size and less(self.heap[j], self.heap[j + 1]): j += 1 if not less(self.heap[k], self.heap[j]): break exch(self.heap, k, j) k = j
def delete(self): max = self.heap[1] exch(self.heap, 1, self.size) self.size -= 1 self._sink(1) return max
def _swim(self, k): while k > 1 and less(self.heap[k / 2], self.heap[k]): exch(self.heap, k / 2, k) k = k / 2