Skip to content

Commit 1cfe245

Browse files
semalPatelkeon
authored andcommitted
edit swap one liner (keon#458)
1 parent 7a859d2 commit 1cfe245

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

algorithms/heap/binary_heap.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def perc_up(self, i):
5959
while i // 2 > 0:
6060
if self.heap[i] < self.heap[i // 2]:
6161
# Swap value of child with value of its parent
62-
tmp = self.heap[i]
63-
self.heap[i] = self.heap[i // 2]
64-
self.heap[i // 2] = tmp
62+
self.heap[i], self.heap[i//2] = self.heap[i//2], self.heap[i]
6563
i = i // 2
6664

6765
"""
@@ -95,9 +93,7 @@ def perc_down(self, i):
9593
min_child = self.min_child(i)
9694
if self.heap[min_child] < self.heap[i]:
9795
# Swap min child with parent
98-
tmp = self.heap[min_child]
99-
self.heap[min_child] = self.heap[i]
100-
self.heap[i] = tmp
96+
self.heap[min_child], self.heap[i] = self.heap[i], self.heap[min_child]
10197
i = min_child
10298
"""
10399
Remove Min method removes the minimum element and swap it with the last

0 commit comments

Comments
 (0)