In Class: Week 13

Create a week13 subdirectory in your cs21/class directory and copy over some starting point files:

    $ cd 
    $ cd cs21/class
    $ pwd
    $ mkdir week13       
    $ cd week13
    $ pwd
    $ cp ~newhall/public/cs21/week13/* .
    $ ls

This week and next week we are going to cover linked lists. We will talk about operations on linked lists and look at an implementation of Node and LinkedList classes to which we will add functionality.

  1. We will start by looking at the Node class defined in
  2. Linked list nodes have a special data field, next, that refers to the next node in the linked list.

  3. Next, we will look at the linked list class. A linked list object has three data members: head points to the first Node in the list; tail points to the last Node in the list; and size, is the number of values (Nodes) in the list. Minimally, a linked list needs one data field, head, to point to the head of the list, but often it has these other two additional fields to make some operations faster
  4. We are going to talk about several operations on a linked list, and implement some of the following missing LinkedList method functions:

    1. insertAtTail(val): add a new node to the end of the linked list
    2. insertAtHead(val): add a new node at the front of the linked list
    3. 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
    4. __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)
    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