summaryrefslogtreecommitdiff
path: root/hw2
diff options
context:
space:
mode:
Diffstat (limited to 'hw2')
-rw-r--r--hw2/__pycache__/assignment_lists_sp23.cpython-310.pycbin0 -> 7427 bytes
-rw-r--r--hw2/assignment_lists_sp23.py17
2 files changed, 11 insertions, 6 deletions
diff --git a/hw2/__pycache__/assignment_lists_sp23.cpython-310.pyc b/hw2/__pycache__/assignment_lists_sp23.cpython-310.pyc
new file mode 100644
index 0000000..cac7ac9
--- /dev/null
+++ b/hw2/__pycache__/assignment_lists_sp23.cpython-310.pyc
Binary files differ
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