CS 12 -- Lab 4

Today's lab will be part lecture, part lab. We will introduce linked lists -- structures that, like arrays, are used to store data. Unlike arrays, linked lists only need to be as large as the data being stored, and allow for easy reordering. We'll see how to make them in Java, and then try some fancy manipulation.

See the solution.


Your assignment

Assuming that you've already heard the mini-lecture on linked lists, you must write a program that does the following:

  1. Accept a line of input from the keyboard as a String. (Use the User.readLine() method.)

  2. Convert the String into a singly linked list of char.

  3. Traverse and output the contents of that list.

  4. Reverse the linked list. This step must be done recursively and in place -- that is, without allocating any new links.

  5. Traverse and output the contents of the now-reversed list.

You should write this program first by creating a instantiable CharLinkNode class. An object of this class will hold single char and a pointer to another link. Then, you should write a static ListReverse class that will contain the rest of your code and use CharLinkNode for building its list.


What you must submit

Once you have written and tested CharLinkNode and ListReverse, you must use the cs12-submit command to turn in your Java code. Submit this assignment as lab-4 when you use the cs12-submit command.


This assignment is due on Sunday, October 12th, at 11:59 pm.

Scott F. Kaplan
Last modified: Sun Nov 5 22:48:52 EST 2000