Homework 3: Recursive Linked Lists

This is the archived website of IC 312 from the Fall 2014 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

For this assignment, you will use recursion to write some linked list methods. You have to complete all the methods in the Recursion class.

Starter code

You can get all these files at once by downloading the file hw03.tar.gz and running tar xzvf hw03.tar.gz


I have made a Tester class with a main method that performs a couple tests, but you should make your own main method to test your solutions as well. I will test on all kinds of weird inputs, and so should you! Like running longest on an empty list, or using an index too large for the list; your program should handle those correctly.

The methods to be finished are:

  • add2front(): self explanatory. There's no recursion to be done here.
  • printInOrder(): Print out the elements of the list, in the order they appear in the list, from first node to last node. You'll need a helper method with a different signature to do this (I have started it for you).
  • printInReverseOrder(): Print out the elements of the list, from last to first. Again, you'll need a helper method.
  • longest(): Return (not print), the longest string in the list. Helper needed.
  • get(int i): Return (not print), the element in the i-th link. Helper needed.
  • remove(int i): Excise the i-th link from the list. Helper needed.

If you don't remember recursion well, this might take you a while. Please don't wait to start until the night before.

It is not necessary to submit your class with a main method, as I'll use my own for grading; it won't break anything to include it, though. Again keep in mind that I will grade you based on much more than what the Tester class does!