gshute.ioutil
Class CircularList

java.lang.Object
  |
  +--gshute.ioutil.CircularList

public class CircularList
extends java.lang.Object

A CircularList is a list with its far end linked to its near end. Data items can be added or retrieved from either end. Data items can be removed from the front. The first data item can be rotated to the far end. One CircularList can be appended to another CircularList. A CircularList can be used to implement various data structures.


Inner Class Summary
 class CircularList.Node
          A Node is a building block for circular linked lists.
 
Field Summary
protected  CircularList.Node tail
          tail is a reference to the last Node in this CircularList.
 
Constructor Summary
CircularList()
          CircularList() returns an empty CircularList.
CircularList(java.lang.Object dat)
          CircularList(dat) returns a CircularList with a single data item dat.
 
Method Summary
 void addFirst(java.lang.Object dat)
          cl.addFirst(dat) adds dat as the first data item in cl.
 void addLast(java.lang.Object dat)
          cl.addLast(dat) adds dat as the last data item in cl.
 void append(CircularList cl1)
          cl.append(cl1) appends cl1 onto the end of cl and makes cl1 empty.
 java.lang.Object getFirst()
          cl.getFirst() returns the first data item in cl.
 java.lang.Object getLast()
          cl.getLast() returns the last data item in cl.
 boolean isEmpty()
          cl.isEmpty() returns true if cl is empty.
 void removeFirst()
          cl.removeFirst() removes the first data item from cl.
 void rotate()
          cl.rotate() rotates the first data item in cl to the end of cl.
 java.lang.String toString()
          cl.toString() returns a string describing the data in cl.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tail

protected CircularList.Node tail
tail is a reference to the last Node in this CircularList.
Constructor Detail

CircularList

public CircularList()
CircularList() returns an empty CircularList.

CircularList

public CircularList(java.lang.Object dat)
CircularList(dat) returns a CircularList with a single data item dat.
Method Detail

isEmpty

public boolean isEmpty()
cl.isEmpty() returns true if cl is empty.

getFirst

public java.lang.Object getFirst()
cl.getFirst() returns the first data item in cl.

Preconditions:
cl.isEmpty() is false.


getLast

public java.lang.Object getLast()
cl.getLast() returns the last data item in cl.

Preconditions:
cl.isEmpty() is false.


addFirst

public void addFirst(java.lang.Object dat)
cl.addFirst(dat) adds dat as the first data item in cl.

addLast

public void addLast(java.lang.Object dat)
cl.addLast(dat) adds dat as the last data item in cl.

removeFirst

public void removeFirst()
cl.removeFirst() removes the first data item from cl.

Preconditions:
cl.isEmpty() is false.


rotate

public void rotate()
cl.rotate() rotates the first data item in cl to the end of cl.

append

public void append(CircularList cl1)
cl.append(cl1) appends cl1 onto the end of cl and makes cl1 empty.

toString

public java.lang.String toString()
cl.toString() returns a string describing the data in cl.
Overrides:
toString in class java.lang.Object