MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __swap_up

Method __swap_up

data_structures/heap/max_heap.py:23–30  ·  view source on GitHub ↗

Swap the element up

(self, i: int)

Source from the content-addressed store, hash-verified

21 self.__size = 0
22
23 def __swap_up(self, i: int) -> None:
24 """Swap the element up"""
25 temporary = self.__heap[i]
26 while i // 2 > 0:
27 if self.__heap[i] > self.__heap[i // 2]:
28 self.__heap[i] = self.__heap[i // 2]
29 self.__heap[i // 2] = temporary
30 i //= 2
31
32 def insert(self, value: int) -> None:
33 """Insert new element"""

Callers 1

insertMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected