__getitem__
and __setitem__
methods of the LinkedList class. Test your methods to
make sure that they work as expected. __getitem__
and __setitem__
is the same. Each method
needs to handle negative index values, raise an
IndexError if the index is out of the allowed range,
and obtain the _ListNode
at the
appropriate position. It makes sense to write a
helper method that handles these common tasks. The
following provides a starting point:
def _nodeAt(self, indx): # Returns the _ListNode at position indx. # Raises an IndexError if the index is out of range.Once
_nodeAt
is completed, __getitem__
and __setitem__
should each require at most two lines of
code.
insert
method. One way of organizing this method is to work
through the following steps:
There is nothing to hand in for this assignment. Make sure that you save a copy of your code.