1 parent 7a859d2 commit 1cfe245Copy full SHA for 1cfe245
1 file changed
algorithms/heap/binary_heap.py
@@ -59,9 +59,7 @@ def perc_up(self, i):
59
while i // 2 > 0:
60
if self.heap[i] < self.heap[i // 2]:
61
# 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
+ self.heap[i], self.heap[i//2] = self.heap[i//2], self.heap[i]
65
i = i // 2
66
67
"""
@@ -95,9 +93,7 @@ def perc_down(self, i):
95
93
min_child = self.min_child(i)
96
94
if self.heap[min_child] < self.heap[i]:
97
# Swap min child with parent
98
- tmp = self.heap[min_child]
99
- self.heap[min_child] = self.heap[i]
100
- self.heap[i] = tmp
+ self.heap[min_child], self.heap[i] = self.heap[i], self.heap[min_child]
101
i = min_child
102
103
Remove Min method removes the minimum element and swap it with the last
0 commit comments