Starting from:
$30

$24

Linked List

Here is a description of what you need to do:

Create the linked list class as we did during our lecture. All the operations should be implemented. Make sure your code is bug free – even if we had a bug in the code we discussed in class!

After that, add methods in the class to support the following new operations:

1.1    Length

Add a function called len that returns the length of the list i.e. the number of elements in the list. The logic is simple: loop over the whole list and keep track of a counter. At the end, return the counter.

1.2    Index-based Retrieval

Add a function called get that takes one parameter – an index – and returns the value at that index. For instance, if we have a list lst:
[1, 2, 5, 4, 2]
and we call lst.get(2), it should return 5. If the function is given an index that does not exist (i.e. is beyond the limit of the list), the function should raise an IndexError type exception. For instance, calling get(10) on the list above should result in an IndexError exception with a meaningul message.

The logic for the retrieval is again quite simple: loop over the whole list and keep track of a counter. When the counter reaches the desired value, simply return the value at that position. If we reach the end of the list, it means we have an IndexError.

    • Submission

Use python run.py local to ensure all tests are passing and then submit your assignment using python run.py

remote
If you wish to request an extension, use the autograder UI to do so. Each student gets a maximum of 3 extension days per semester.







More products