CS 210  Homework #5   

   assigned 10 Oct, due 17 Oct
(+2 bonus if submitted by 15 Oct)



The purpose of this assignment is to get a bit more practice/experience dealing with lists, and also to brush off your ability to do a simple sort.  (note that the sorting operation requires being able to add and delete elements from the list)

1.  Read in a bunch of values
  (suggest: use the StreamTokenizer as before, and select the "TT_WORD" items)

2.  Store those items into a doubly-linked list.  At this time, the list should NOT be ordered.
  (perhaps you'd find it easier to have the list elements hold just Strings ... just pull out the sval from the Token and put that into the list)

  You can read about doubly-linked lists in Lafore, and even find some code to work with.

2b. print out the list after step 2.

----- test this.  Make sure you can print the list in a reasonable way.



----- proceed to 3 only after the previous section is working

3.  now sort the list in place using a regular insertion sort.  Print it out.
  (note: this sort should take the list elements created in (2) and move them around ... sometimes deleting one from one position and reinserting it elsewhere.)
  (it is possible to put a list "in order" by creating a new, ordered list and transferring all the elements into it.  That's not what's asked for here.)

3a.  Suggest you pause and look at the class you created for step 2.  Does it have the capabilities you'll need for the sort?  If not, better add them -- and test them -- before you try to get the sort working.
  You can put the "sort" function inside of the Doubly-Linked List class if you want, or outside.  In any case, be careful about operations at the ends of the list.


Note:  If you're putting Strings in the list, you can use s.compareTo(y) to compare them during the sort.  If your list holds Tokens, this can still work, just you'll need to look a bit further to get to the "sval" field... or you can add a method,
  
      boolean compareTo(Token t) 
to Token, and call that.

  You can read about insertion sort in Lafore, and probably find some code you can work with.  Make sure you understand how this works (esp. if you didn't finish assignment #2) ... use the animated applet to watch it in action, perhaps run Lafore's code with some extra println statements.




Please Note:


Put your name at the front of every file (especially the main program).  This is a help to the grader, allows him to spend his time productively.

Please use the SCP/ssh mechanism to submit this assignment.  (If you've not yet gotten a UNIX account, please do so asap.)  Some people are a little unsure of how this works.
Thank you.