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
- Write a recursive method that prints k dots on the terminal.
- 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.
- 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.)
-
A non-recursive method to return the length of a linked list.
-
A method to return the nth value in a linked list.
-
A method to print a linked list of floating point values.
-
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).
-
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:
- sum all the values in a linked list of doubles.
- determine whether a linked list of doubles
contains a value greater than k.
- return the last value in a linked list.
- return the nth value in a linked list.
Extra problems if you have extra time
-
Write a method to add an element onto the end of a linked list.
-
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