CS 102
Assignment #2
Due at 11:59PM on Sunday, September 30. Packaging instructions are on
the course webpage.
Read sections 3.2--3.5 of the textbook. Then solve the following
programming problem in Java.
Input: a non-negative integer X, and a non-empty circularly linked
list with singly-linked nodes. Each node contains a string. Some
of the strings might be identical.
Output: the string in the node that represents the result of a modulus
operation on the list. Think of the elements of the list as
representing the first N non-negative integers, where the names of the
integers are arbitrary strings rather than "0", "1", "2", etc.. You
have no way of determining N, but you have to compute (X mod N).
Here's the catch: You may not use any other data structures (including
arrays), you may not compute the size of the list, and you may not
modify the input list in any way other than moving the cursor. This
means that you may not use the size(), add() and remove() methods.
Instead, solve the problem by link hopping.
In the comments at the top of your submission, indicate the big-Oh
running time of your algorithm, in terms of all relevant variables.
For the purpose of this assignment, download and use the textbook's
code fragments 3.12 and 3.25 from the textbook's website. After
downloading these code fragments, write a method for creating a
circular list and populating it with strings from a file, which you
will use to test your solution. (You can use Professor Marateck's
FileStringReader class for this purpose -- I asked for and received
his permission. See
http://www.cs.nyu.edu/courses/fall00/V22.0101-003/FileStringReader.java
) Then write the solution to the problem above. Then wrap everything
(including your testing method(s)) in a complete Java program that you
can compile, run, and test on different inputs.