Java Reference
In-Depth Information
LISTING 13.1
//*******************************************************************
// MagazineRack.java Author: Lewis/Loftus
//
// Driver to exercise the MagazineList collection.
//*******************************************************************
public class MagazineRack
{
//----------------------------------------------------------------
// Creates a MagazineList object, adds several magazines to the
// list, then prints it.
//----------------------------------------------------------------
public static void main (String[] args)
{
MagazineList rack = new MagazineList();
rack.add ( new Magazine("Time"));
rack.add ( new Magazine("Woodworking Today"));
rack.add ( new Magazine("Communications of the ACM"));
rack.add ( new Magazine("House and Garden"));
rack.add ( new Magazine("GQ"));
System.out.println (rack);
}
}
OUTPUT
Time
Woodworking Today
Communications of the ACM
House and Garden
GQ
Other methods could be included in the MagazineList ADT. For example, in
addition to the add method provided, which always adds a new magazine to the
end of the list, another method called insert could be defined to add
a node anywhere in the list (to keep it sorted, for instance). A param-
eter to insert could indicate the value of the node after which the
new node should be inserted. Figure 13.2 shows how the references
would be updated to insert a new node.
KEY CONCEPT
Insert and delete operations can be
implemented by carefully manipulat-
ing object references.
Search WWH ::




Custom Search