Java Reference
In-Depth Information
LISTING 13.2
//*******************************************************************
// MagazineList.java Author: Lewis/Loftus
//
// Represents a collection of magazines.
//*******************************************************************
public class MagazineList
{
private MagazineNode list;
//----------------------------------------------------------------
// Sets up an initially empty list of magazines.
//----------------------------------------------------------------
public MagazineList()
{
list = null ;
}
//----------------------------------------------------------------
// Creates a new MagazineNode object and adds it to the end of
// the linked list.
//----------------------------------------------------------------
public void add (Magazine mag)
{
MagazineNode node = new MagazineNode (mag);
MagazineNode current;
if (list == null )
list = node;
else
{
current = list;
while (current.next != null )
current = current.next;
current.next = node;
}
}
//----------------------------------------------------------------
// Returns this list of magazines as a string.
//----------------------------------------------------------------
public String toString ()
Search WWH ::




Custom Search