mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
a92936bd01
commit
071ce716e4
|
@ -12,6 +12,7 @@ Operations supported:
|
||||||
- Merge: O(1)
|
- Merge: O(1)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
"""
|
"""
|
||||||
A node in a Fibonacci heap.
|
A node in a Fibonacci heap.
|
||||||
|
@ -28,6 +29,7 @@ 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
|
||||||
|
@ -231,7 +233,7 @@ class FibonacciHeap:
|
||||||
|
|
||||||
This is an internal method that maintains the heap's structure.
|
This is an internal method that maintains the heap's structure.
|
||||||
"""
|
"""
|
||||||
max_degree = int(self.size ** 0.5) + 1
|
max_degree = int(self.size**0.5) + 1
|
||||||
degree_table = [None] * max_degree
|
degree_table = [None] * max_degree
|
||||||
|
|
||||||
# Collect all roots
|
# Collect all roots
|
||||||
|
@ -299,7 +301,7 @@ class FibonacciHeap:
|
||||||
Args:
|
Args:
|
||||||
node: Node to be cut.
|
node: Node to be cut.
|
||||||
parent: Parent of the node to be cut.
|
parent: Parent of the node to be cut.
|
||||||
""""""
|
""" """
|
||||||
Performs cascading cut operation.
|
Performs cascading cut operation.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -324,8 +326,7 @@ class FibonacciHeap:
|
||||||
node: Starting node for cascading cut.
|
node: Starting node for cascading cut.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parent = node.parent
|
if parent := node.parent:
|
||||||
if parent:
|
|
||||||
if not node.mark:
|
if not node.mark:
|
||||||
node.mark = True
|
node.mark = True
|
||||||
else:
|
else:
|
||||||
|
@ -359,4 +360,5 @@ class FibonacciHeap:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user