Singly-linked list/Element definition: Difference between revisions

Add itertion support to node
(Python version taken from transversal page)
(Add itertion support to node)
Line 167:
==[[Python]]==
[[Category:Python]]
 
The Node class implements also iteration for more Pythonic iteration over linked lists.
 
<pre>
Line 173 ⟶ 175:
self.value = value
self.next = next
def __iter__(self):
node = self
while node:
yield node
node = node.next
</pre>
 
Anonymous user