Introduction to OOP: Chapter 8: The Solitaire Game [next] [previous] [audio] [real] [text]

Linked List class

class LinkedList {
	public LinkedList () { firstLink = null; }

	public void add (Object newValue)
		{ firstLink = new Link(newValue, firstLink); }

	public boolean empty ()
		{ return firstLink == null; }

	public Object front ()
		{  if (firstLink == null)
			return null;
		  return firstLink.value(); }

	public void pop ()
		{ if (firstLink != null) 
			firstLink = firstLink.next(); }

	public ListIterator iterator ()
		{ return new ListIterator (firstLink); }

	private Link firstLink;
}
Intro OOP, Chapter 8, Slide 9