Computer Science 245: Data Structures and Algorithms

Homework 4: Linked Lists (due 2/22/2017)


For your fourth homework assignment, you will extedning an existsing simple linked list class to add some methods. The provided list class uses a dummy element. There are 4 methods that you will need to add:

(5 points) void removeFirst(Object o)

Removes the first occurance of element o in the list. If o does not exists in the list, then this method does nothing. Be sure to handle all cases correctly - removing an element at the beginning, end, and middle of the list! Use .equals (and not ==) to check for equality.

(5 points) void removeLast(Object o)

Removes the last occurance of element o in the list. If o does not exists in the list, then this method does nothing. Be sure to handle all cases correctly - removing an element at the beginning, end, and middle of the list! Use .equals (and not ==) to check for equality. This code should be O(n).

(5 points) void removeAll(Object o)

Removes all occurances of element o in the list. If o does not exists in the list, then this method does nothing. Be sure to handle all cases correctly - removing an element at the beginning, end, and middle of the list! Use .equals (and not ==) to check for equality. This code should be O(n).

(5 points) String toString()

Creates a string representation of the list. The string should be a Left bracket, followed by concatenating the result of toString() called on each element of the list (separated by ", ") follewed by a right bracket. Examples:

Provided files

Submission

Please place your new version of LinkedList.java, along with the (unchanged!) ListNode.java into subversion under:

https://www.cs.usfca.edu/svn/<username>/cs245/homework4/