CS 151 -- Lab 9

Further Extending Linked Lists

Write the following two methods within the linked list class discussed this week.

Code is available at

    https://cs.brynmawr.edu/cs151/Data/Lab9/SingleLinkedList.java
    https://cs.brynmawr.edu/cs151/Data/Lab9/LinkedListInterface.java
        
or via scp at
        /home/gtowell/Public/151/Data/Lab9/SingleLinkedList.java
        /home/gtowell/Public/151/Data/Lab9/LinkedListInterfaqce.java
        

        /**
        * Determine if the list contains the provided object. 
        * @param r the object to be looked for.
        * @return true iff the object is in the linked list.
        */
       boolean contains(J r);
   
       /**
       * Given a linked list whose items are in sorted order,
       * add the new item, r, so that the items in the linked list are 
       * still in sorted order after the addition.  
       * @param: r  the item to be added 
       * @return true iff the addition succeeded (it will always succeed).
       **/
       boolean addSorted(J r);
    

It is probably easiest to write/test these functions using Strings. For instance for the contains method, make a linked lists that can contain String. Then add a bunch of strings into it (using add first or add last), then test the contains method. Likewise for addSorted.

Not required, but recommended, write a main function that uses that two functions you wrote and verifies that your functions actually work.

What to turn in

Send email to gtowell@brynmawr.edu with the two functions (or as much of the two functions are you complete in 80 minutes).