Question
In algorithms, in python, if we have a Node class and a LinkedList class that uses it (and abstracts Node's inner wroking/pointers), how do we iterate over the data of all the Nodes in the LinkedList class without taking away the abstraction of the inner working of Node?
via a generator function defined in LinkedList class.
here is example (this is not needed to pass this test :) :
class LinkedList(object):
...
def iter(self):
current = self.tail
while current:
val = current.data
current = current.next
yield val

Question
In algorithms, in python, if we have a Node class and a LinkedList class that uses it (and abstracts Node's inner wroking/pointers), how do we iterate over the data of all the Nodes in the LinkedList class without taking away the abstraction of the inner working of Node?
?

Question
In algorithms, in python, if we have a Node class and a LinkedList class that uses it (and abstracts Node's inner wroking/pointers), how do we iterate over the data of all the Nodes in the LinkedList class without taking away the abstraction of the inner working of Node?
via a generator function defined in LinkedList class.
here is example (this is not needed to pass this test :) :
class LinkedList(object):
...
def iter(self):
current = self.tail
while current:
val = current.data
current = current.next
yield val

If you want to change selection, open document below and click on "Move attachment"

#### pdf

owner: kkhosravi - (no access) - PYTHON_DATA_STRUCTURES_AND_ALGORITHMS.pdf, p111

#### Summary

status measured difficulty not learned 37% [default] 0

No repetitions