CSE 131 Module 8: List Structures

Given Quiz

Name (print CLEARLY) ___________________________________   Lab Section you attend______________

CSE131 Quiz 8
List Structures
7 Nov 2008

public static ListItem palin(ListItem ls) {
    ListItem ans = new ListItem(0, null);
    return helper(ans, ls, ans, null);

public static ListItem helper(ListItem ans, 
                              ListItem original,
              ListItem endForward, ListItem begBack) {

    if (original == null) {
        endForward.next = begBack;
        return ans;
    else {
        endForward.next = new ListItem(original.number, null);
        begBack         = new ListItem(original.number, begBack);
        return helper(ans, original.next, endForward.next, begBack);
Consider the above code and the list (1, 2, 3, 4) created by:
   ListItem list = new ListItem(1,
                      new ListItem(2,
                        new ListItem(3,
                          new ListItem(4, null))));
  1. Is the code executed by calling palin (circle one on each line below):
  2. Draw the list structure returned by the static method call: (you need not show memory addresses, just draw bubbles, numbers, and links)
  3. The structure you show above should be slightly off in terms of what really should be returned by palin. Mark up one line of the code to show how to fix that problem.

Solution not yet available.