This lab will help you learn more about linked lists as well as classification. in the package stringList you will develop a new class stringLinkedListSortedItr that extends stringLinkedListItr and enables us to mainatain a sorted list of strings.
cd public-html/classes/csc241
cp -r ~mohammad/public-html/classes/csc241/stringList .
-- don't forget the dot or the -r. This command replicates my stringList directory and places it in your account.
The following should be used as a template in creating this new class. Note that the other methods from stringLinkedListItr are simply inherited as well as the variables current_ and myList_.
public class stringLinkedListSortedItr extends stringLinkedListItr { public stringLinkedListSortedItr( stringLinkedList anyList ) { super(anyList); } public void insert( String x ) { /* if no elements in mylist_ construct a listNode with mylist_.header_ referencing it with x and null as parameters. return. if x is smaller than element_ in mylist_.header_ construct a listNode with mylist_.header_ referencing it with x and mylist_.header_ as parameters. return. ListNode temp=mylist_.header_; while (temp.next_ != null && x is larger than element_ in temp.next_) temp=temp.next_; construct a listNode with temp.next_ referencing it with x as the 1st parameter and the appropriate second parameters. return. */ } public void insertAtBeginning( String x ) { /*Do Nothing--insertAtBeginning will act as no-op for this class */ } }
Using test2.java as a model develop a test program for stringLinkedListSortedItr. If you use the same set of insert and remove statements from test2.java, your expected output will be:
>java testSort Size is 6 1 2 3 4 5 7 After removing 3 things Size is 3 4 5 7