mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-16 02:37:36 +00:00
Added tests and docstrings to fibonacci_heap.py
This commit is contained in:
parent
071ce716e4
commit
bd943b086a
@ -12,7 +12,6 @@ Operations supported:
|
|||||||
- Merge: O(1)
|
- Merge: O(1)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
"""
|
"""
|
||||||
A node in a Fibonacci heap.
|
A node in a Fibonacci heap.
|
||||||
@ -29,7 +28,6 @@ class Node:
|
|||||||
degree: Number of children.
|
degree: Number of children.
|
||||||
mark: Boolean indicating if node has lost a child.
|
mark: Boolean indicating if node has lost a child.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self.val = val
|
self.val = val
|
||||||
self.parent = None
|
self.parent = None
|
||||||
@ -326,7 +324,8 @@ class FibonacciHeap:
|
|||||||
node: Starting node for cascading cut.
|
node: Starting node for cascading cut.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if parent := node.parent:
|
parent = node.parent
|
||||||
|
if parent:
|
||||||
if not node.mark:
|
if not node.mark:
|
||||||
node.mark = True
|
node.mark = True
|
||||||
else:
|
else:
|
||||||
@ -360,5 +359,4 @@ class FibonacciHeap:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user