Пример #1
0
 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
Пример #2
0
 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