In Class: Week 13


We are going to continue using the linklisted.py code from week 12 this week. If you have not already done so, create a week13 subdirectory in your cs21/class directory. You can either copy your linkedlist.py from your week 12 directory OR start with a fresh copy:

    $ cd
    $ cd cs21/class
    $ pwd
      /home/your_user_name/cs21/class
    $ mkdir week13
    $ cd week13
    $ pwd
      /home/your_user_name/cs21/class/week13
    $ cp ~turnbull/public/cs21/week13/* .
    $ ls
      linkedlist.py
  

We are going to implement several method functions of the LinkedList class and test them as we go.
  1. insertAtTail(val): add a new node to the end of the linked list. We wrote this code together on Friday, but take another look.
  2. __str__: complete this method that will create a string version of the linked list. We will try calling it from main, by calling print str(list)
  3. insertAtHead(val): add a new node at the front of the linke list
  4. findElement(val): find a matching element in the linked list, returns a reference to the Node with a matching data field or None if no matching value exists in the linked list
  5. insertSorted(val): add a new node in sorted order into the linked list. We will use insertion Sort to find the correct insertion spot for the new element
  6. removeFromHead(): remove the first element from the linked list and returns the value of its data field or None if the list is empty
  7. removeFromTail(): remove the last element from the linked list and returns the value of its data field or None if the list is empty