forked from heineman/LearningAlgorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
28 lines (21 loc) · 612 Bytes
/
node.py
File metadata and controls
28 lines (21 loc) · 612 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
27
28
"""Class represents a node in a linked list."""
class Node:
"""
Node structure to use in linked list.
"""
def __init__(self, val, rest=None):
self.value = val
self.next = rest
def __str__(self):
return '[{}]'.format(self.value)
def __iter__(self):
"""
Generator to retrieve values in linked list in order.
Enabled Python code like following, where alist is a Node.
for v in alist:
print(v)
"""
yield self.value
if self.next:
for v in self.next:
yield v