Skip to content

Commit

Permalink
edit swap one liner (keon#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
semalPatel authored and keon committed Dec 11, 2018
1 parent 7a859d2 commit 1cfe245
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions algorithms/heap/binary_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def perc_up(self, i):
while i // 2 > 0:
if self.heap[i] < self.heap[i // 2]:
# Swap value of child with value of its parent
tmp = self.heap[i]
self.heap[i] = self.heap[i // 2]
self.heap[i // 2] = tmp
self.heap[i], self.heap[i//2] = self.heap[i//2], self.heap[i]
i = i // 2

"""
Expand Down Expand Up @@ -95,9 +93,7 @@ def perc_down(self, i):
min_child = self.min_child(i)
if self.heap[min_child] < self.heap[i]:
# Swap min child with parent
tmp = self.heap[min_child]
self.heap[min_child] = self.heap[i]
self.heap[i] = tmp
self.heap[min_child], self.heap[i] = self.heap[i], self.heap[min_child]
i = min_child
"""
Remove Min method removes the minimum element and swap it with the last
Expand Down

0 comments on commit 1cfe245

Please sign in to comment.