-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnode.py
More file actions
26 lines (23 loc) · 749 Bytes
/
node.py
File metadata and controls
26 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Node class for Disjoint-set data structure with Union-Find algorithms
----------------------------------------------------------------------
Jack Lawrence-Jones, July 2016
"""
class Node(object):
"""
Private tree node class.
Node:
value: the node's value
parent: reference to the node's parent
rank: the rank of the tree (only valid if node is a root)
"""
# Constructor
def __init__(self, value):
self.value = value
self.parent = self # Node is its own parent, therefore it's a root node
self.rank = 0 # Tree of single node has rank 0
# Print format for debugging
def __str__(self):
st = "[value: " + str(self.value) + ", parent: " + str(self.parent.value)
st += ", rank: " + str(self.rank) + "]"
return st