Recursive Linked List |
Recall that the recursive Scribbles and Target programs had very similar structures. That structure corresponds to a linear list.
The following demo program includes an interface List and two classes implementing it: EmptyList and NonEmptyList. Recursive List.
Notice that the methods that change the list return a reference to the new list. After those operations, the reference to the old list need not be meaningful.
Recursive Linked List |