com.stepsoncats.gublists
Class Lklist

java.lang.Object
  |
  +--com.stepsoncats.gublists.Lklist

public class Lklist
extends java.lang.Object

A Lklist is a simple doubly-linked list. Linked list libraries typically enable you to insert some item of data into a list; the list methods automatically wrap the data item in a list element and return the element to you. Lklist is instead built on a model of creating a list element of a particular type (a subclass of the LklistElt base class) to contain a data item and then inserting that list element into some list; the contents of the linked list can be completely heterogeneous. The Lklist class provides the methods for populating, using, and depopulating the list. The LklistElt base class provides no methods other than the constructor.


Constructor Summary
Lklist()
          Construct an empty linked list.
 
Method Summary
 void append(LklistElt elt)
          Insert the specified element at the back of the list, that is, following the last element in the list.
 int countOfElements()
          Return the number of elements in the list.
 LklistElt elementAfter(LklistElt elt)
          Return the list element that immediately follows the specified element.
 LklistElt elementBefore(LklistElt elt)
          Return the list element that immediately precedes the specified element.
 void extract(LklistElt elt)
          Remove the specified element from the list.
 LklistElt extractFirst()
          Remove the first element from the list.
 LklistElt firstElement()
          Return the first element of the list.
 void insertAfter(LklistElt oldElt, LklistElt newElt)
          Insert the specified new list element after the specified existing list element.
 void insertBefore(LklistElt oldElt, LklistElt newElt)
          Insert the specified new list element before the specified existing list element.
 LklistElt lastElement()
          Return the last element of the list.
 void prepend(LklistElt elt)
          Insert the specified element at the front of the list, that is, preceding the first element in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lklist

public Lklist()
Construct an empty linked list.
Method Detail

firstElement

public LklistElt firstElement()
Return the first element of the list.
Returns:
The first element in the list.

lastElement

public LklistElt lastElement()
Return the last element of the list.
Returns:
The last element in the list.

countOfElements

public int countOfElements()
Return the number of elements in the list.
Returns:
The number of elements in the list.

elementBefore

public LklistElt elementBefore(LklistElt elt)
Return the list element that immediately precedes the specified element.
Parameters:
elt - The list element that immediately follows the one you want.
Returns:
The list element preceding elt.

elementAfter

public LklistElt elementAfter(LklistElt elt)
Return the list element that immediately follows the specified element.
Parameters:
elt - The list element that immediately precedes the one you want.
Returns:
The list element following elt.

prepend

public void prepend(LklistElt elt)
Insert the specified element at the front of the list, that is, preceding the first element in the list. Equivalent to insertBefore(firstElement(), elt).
Parameters:
elt - The list element to insert into the list.

append

public void append(LklistElt elt)
Insert the specified element at the back of the list, that is, following the last element in the list. Equivalent to insertAfter(lastElement(), elt).
Parameters:
elt - The list element to insert into the list.

insertBefore

public void insertBefore(LklistElt oldElt,
                         LklistElt newElt)
Insert the specified new list element before the specified existing list element.
Parameters:
oldElt - The list element that should immediately follow the new list element, after the new element has been inserted into the list.
newElt - The new list element to insert into the list.

insertAfter

public void insertAfter(LklistElt oldElt,
                        LklistElt newElt)
Insert the specified new list element after the specified existing list element.
Parameters:
oldElt - The list element that should immediately precede the new list element, after the new element has been inserted into the list.
newElt - The new list element to insert into the list.

extract

public void extract(LklistElt elt)
Remove the specified element from the list.
Parameters:
elt - The list element to remove from the list.

extractFirst

public LklistElt extractFirst()
Remove the first element from the list. This is a convenience function that combines the firstElement() and extract() methods: it removes the first element from the list and returns it.
Returns:
elt The first list element in the list, now removed from the list.


Copyright 2003 Steps On Cats