Lab 14
Version 1

Be aware that this is a first-draft document. Please report any bugs to fleck@cs.hmc.edu.

Problems using recursion

  1. Write a recursive method that prints k dots on the terminal.
  2. Write a recursive method that takes a double x and an integer k as input and computes x to the kth power.

Problems using linked lists

Write the following methods and test them by adapting the linked list code from the notes.

  1. A method that takes a linked list and returns the same list missing its first node. (The output list will share nodes with the input list.)
  2. A non-recursive method to return the length of a linked list.
  3. A method to return the nth value in a linked list.
  4. A method to print a linked list of floating point values.
  5. A method to read in floating point values from the user, stopping when the user types in a negative number. This method should return a linked list of the input values (not including the negative number).
  6. A method to compute the average of the values in the list from the above method.

Recursive methods for linked lists

Write recursive methods that do the following:

  1. sum all the values in a linked list of doubles.
  2. determine whether a linked list of doubles contains a value greater than k.
  3. return the last value in a linked list.
  4. return the nth value in a linked list.

Extra problems if you have extra time

  1. Write a method to add an element onto the end of a linked list.
  2. A method to make a copy of a linked list. (The copy is made of newly created nodes, not nodes from the input list.)

Last modified Nov 24 199 for Fall 99 cs5 by fleck@cs.hmc.edu