mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Added doctest to randomized_heap.py (#11151)
This commit is contained in:
parent
a13e9c2137
commit
8b7352626e
|
@ -22,14 +22,40 @@ class RandomizedHeapNode(Generic[T]):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self) -> T:
|
def value(self) -> T:
|
||||||
"""Return the value of the node."""
|
"""
|
||||||
|
Return the value of the node.
|
||||||
|
|
||||||
|
>>> rhn = RandomizedHeapNode(10)
|
||||||
|
>>> rhn.value
|
||||||
|
10
|
||||||
|
>>> rhn = RandomizedHeapNode(-10)
|
||||||
|
>>> rhn.value
|
||||||
|
-10
|
||||||
|
"""
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def merge(
|
def merge(
|
||||||
root1: RandomizedHeapNode[T] | None, root2: RandomizedHeapNode[T] | None
|
root1: RandomizedHeapNode[T] | None, root2: RandomizedHeapNode[T] | None
|
||||||
) -> RandomizedHeapNode[T] | None:
|
) -> RandomizedHeapNode[T] | None:
|
||||||
"""Merge 2 nodes together."""
|
"""
|
||||||
|
Merge 2 nodes together.
|
||||||
|
|
||||||
|
>>> rhn1 = RandomizedHeapNode(10)
|
||||||
|
>>> rhn2 = RandomizedHeapNode(20)
|
||||||
|
>>> RandomizedHeapNode.merge(rhn1, rhn2).value
|
||||||
|
10
|
||||||
|
|
||||||
|
>>> rhn1 = RandomizedHeapNode(20)
|
||||||
|
>>> rhn2 = RandomizedHeapNode(10)
|
||||||
|
>>> RandomizedHeapNode.merge(rhn1, rhn2).value
|
||||||
|
10
|
||||||
|
|
||||||
|
>>> rhn1 = RandomizedHeapNode(5)
|
||||||
|
>>> rhn2 = RandomizedHeapNode(0)
|
||||||
|
>>> RandomizedHeapNode.merge(rhn1, rhn2).value
|
||||||
|
0
|
||||||
|
"""
|
||||||
if not root1:
|
if not root1:
|
||||||
return root2
|
return root2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user