-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.py
44 lines (32 loc) · 873 Bytes
/
node.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Implementation of a node.
Useful for trees, linked lists, graphs, etc.
"""
class Node(object):
"""A node for a linked list.
Make a node:
>>> apple = Node("apple")
>>> apple.data
'apple'
>>> print(apple.next)
None
>>> print(apple.prev)
None
And another:
>>> berry = Node("berry")
>>> apple.next = berry
>>> berry.prev = apple
>>> print(apple.next)
<Node berry>
>>> print(berry.prev)
<Node apple>
>>> print(berry.next)
None
"""
def __init__(self, data):
"""Initialize the node's attributes."""
self.data = data
self.next = None
self.prev = None
def __repr__(self):
"""A human-readable representation of a node."""
return "<Node {data}>".format(data=self.data)