diff options
Diffstat (limited to 'hw2/assignment_lists_sp23.py')
| -rw-r--r-- | hw2/assignment_lists_sp23.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/hw2/assignment_lists_sp23.py b/hw2/assignment_lists_sp23.py index 57147d9..a339f1f 100644 --- a/hw2/assignment_lists_sp23.py +++ b/hw2/assignment_lists_sp23.py @@ -67,20 +67,25 @@ class DoublyLinkedList(object): def __iter__(self): """Standard python iterator method""" + self.__current = None return self def __next__(self): """Standard python iterator method""" - if self.current is None: - raise StopIteration() + if self.__current is self.__trailer: + raise StopIteration + + if self.__current is None: + self.__current = self.__header - result = self.current.data - self.current = self.current.next - return result + self.__current = self.__current.next_node + return self.__current def map(self, function): """Run function on every element in the list""" - pass + for n in self: + n.element = function(n.element) + def size(self): """Returns the number of elements in the list""" return self.__size |
