CSC 241- Lab 4 (Due April 7, 2000)


Theme ...

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.


Create directories and copy some files

  1. cd public-html/classes/csc241
  2. 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.

Compile Java files and run the test programs

  1. Use javac to compile each of the .java files, including the files in testList directory.
  2. read test1.java and test2.java in testList and run them to see how we are testing the methods in stringLinkedListItr.

Create the stringLinkedListSortedItr

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 */  }
}

Create the testSort

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

What to Turn In

stringLinkedListSortedItr.java and testSort.java.