CS 2401 Assignment #5

Due Date: Thursday, October 13 or Monday, October 17, 2011, depending on the day of your lab.

Objective: The goal of this assignment is give you additional practice with recursion, by implementing several simple recursive methods.

Part I: Binary Numbers

Write two recursive methods to convert between decimal and binary numbers. The first method should take in a decimal number as a parameter, and print out the binary representation of the given decimal number. The second method should take in a String representing a binary number (with '0' and '1' characters), and print out the corresponding decimal number. Print an error message if you detect any character other than a 1 or 0 in the string.

Part II: Linked Lists

First, write a recursive method that prints out the data elements of a linked list in reverse order. Your method should take in as a parameter the head reference to a linked list. Second, write a recursive method that returns a count of the number of elements greater than a given threshold. You may assume that the data elements in the linked lists are doubles. The parameters of your method are a reference to the linked list and a double value representing the threshold.

Part III: Tracing

For each of the four methods you implemented in parts I and II, trace your code (on paper) for a simple test case that you create. Your test case should require at least 3 recursive calls, but no more than 5. You should be able to explain your trace and how it relates to the code you wrote during your lab demo.