CS 132
Computer Science II
Lab 12 - Drawing From Memory
David B. Levine
Computer Science Department
St. Bonaventure University
Copyright, 2002
Before one can really code using linked structures, one needs to understand how the various Java statements affect dynamically allocated structures. This lab will give you experience tracing such code.
Warning: Some of the code sequences in this lab do something sensible; others attempt to, but fail; still others aren't even trying to behave sensibly. Nonetheless, all of them do something. It is up to you to show the effect of their execution. Determining the intended behavior is not necessary.
PRINTING: There is no need to print the various code fragments. In fact, to save paper you are NOT to print them out in the lab. Each fragment is sufficiently short that working from the screen should not be a hardship.

In each case, you should assume that we are using the same general ListNode structure as in class, i.e.
public class ListNode
{
private int value; // Note slight change of data type
private ListNode next;
public ListNode(int v)
{
value = v;
next = null;
}
public int getValue()
{
return value;
}
public void setValue(int v)
{
value = v;
}
public ListNode getNext()
{
return next;
}
public void setNext(ListNode n)
{
next = n;
}
}
Each code fragment should be viewed separately, i.e. they each work on the diagram above, NOT on the results of the previous fragment. public class TreeNode
{
private String animal; // Note slight change of data type
private TreeNode left;
private TreeNode right;
public TreeNode(String name)
{
animal = name;
left = null;
right = null;
}
public String getAnimal()
{
return animal;
}
public void setAnimal(String n)
{
animal = n;
}
public TreeNode getLeft()
{
return left;
}
public void setLeft(TreeNode t)
{
left = t;
}
public TreeNode getRight()
{
return right;
}
public void setRight(TreeNode t)
{
right = t;
}
}
To Hand In
Hand in your collection of diagrams (which should include more than one per page) along with a cover page.
Assignment Type (see Academic Practices and Policies Document):
Help Policy in Effect for This Assignment: Group Project with Limited Collaboration
In particular, you may discuss the assignment and concepts related to the assignment with the following persons, in addition to an instructor in this course: any member of your group; any St. Bonaventure Computer Science instructor; and any student enrolled in CS 132.
You may use the following materials produced by other students: materials produced by members of your group.
You may use the following materials produced by other students: NONE.