Recursion

Assume that a Node class has been declared, and that every Node has a public "data" field, and a public "next" field for pointing to the next Node in a linked list.

Consider the following recursive method:

     public void printOut (Node s) {
        if (s != null) {
              printOut (s.next);
              System.out.print (s.data + " ");
     }
Assume that printout that the following linked list has been built
   front -> 3 -> 12 -> 77 -> 13 -> 5
and that the call printOut(front) is made.

Question 17

What will be the output generated from this call?

Question 18

How many times in total will printOut be called, including the original call to printOut(front)?
State your answer as a number (e.g. 27).


Previous Home Next