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

Method insert

data_structures/heap/randomized_heap.py:111–123  ·  view source on GitHub ↗

Insert the value into the heap. >>> rh = RandomizedHeap() >>> rh.insert(3) >>> rh.insert(1) >>> rh.insert(3) >>> rh.insert(7) >>> rh.to_sorted_list() [1, 3, 3, 7]

(self, value: T)

Source from the content-addressed store, hash-verified

109 self.insert(item)
110
111 def insert(self, value: T) -> None:
112 """
113 Insert the value into the heap.
114
115 >>> rh = RandomizedHeap()
116 >>> rh.insert(3)
117 >>> rh.insert(1)
118 >>> rh.insert(3)
119 >>> rh.insert(7)
120 >>> rh.to_sorted_list()
121 [1, 3, 3, 7]
122 """
123 self._root = RandomizedHeapNode.merge(self._root, RandomizedHeapNode(value))
124
125 def pop(self) -> T | None:
126 """

Callers 1

__init__Method · 0.95

Calls 2

RandomizedHeapNodeClass · 0.85
mergeMethod · 0.45

Tested by

no test coverage detected