Java Reference
In-Depth Information
FIGURE 30-9
A list and its shallow clone: linked implementation
Chain of nodes
3
numberOfEntries
firstNode
A list
Data in the list
3
numberOfEntries
firstNode
The list's shallow clone
FIGURE 30-10
A list and its deep clone: linked implementation
Chain of nodes
3
numberOfEntries
firstNode
A list
Data in the list
Cloned chain of nodes
3
numberOfEntries
firstNode
The list's deep clone
Cloned data in the list
link, since the list's clone method will set it. With these changes, the revised class Node appears in
LList as follows (changes are highlighted):
public class Node implements Cloneable
{
private T data;
private Node next;
< Constructors >
. . .
< Accessor and mutator methods getData , setData , getNextNode , and setNextNode >
. . .
Search WWH ::




Custom Search