All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class list.List

java.lang.Object
   |
   +----list.List

public class List
extends Object
The List class implements a linked list abstraction. Lists are mutable data structures, which can grow at either end.

Author:
Kathy Yelick

Constructor Index

 o List()
Construct an empty list

Method Index

 o elements()
Returns an Enumeration of the components of this list.
 o insertEnd(Object)
Inserts obj into this list at the end.
 o insertFront(Object)
Inserts obj into this list at the beginning.
 o isEmpty()
Returns true if this list is empty, false otherwise.
 o length()
Returns the length of this list.
 o main(String[])
Runs test cases on the the List class.
 o nth(int)
Returns the element at the specified position.
 o toString()
Returns a String representation of the list.

Constructors

 o List
 public List()
Construct an empty list

Methods

 o isEmpty
 public boolean isEmpty()
Returns true if this list is empty, false otherwise.

Returns:
true if the list is empty, false otherwise.
 o length
 public int length()
Returns the length of this list.

Returns:
the length of the list.
 o insertFront
 public void insertFront(Object obj)
Inserts obj into this list at the beginning.

Parameters:
obj - the object to be inserted.
 o insertEnd
 public void insertEnd(Object obj)
Inserts obj into this list at the end.

Parameters:
obj - the object to be inserted.
 o nth
 public Object nth(int position)
Returns the element at the specified position. If position < 1 or position > length(), then null is returned. Otherwise, the item at position is returned. The list is unchanged in either case.

Parameters:
position - the desired position in the list (between 1 and length()).
Returns:
the Object at the given position in the List.
 o elements
 public Enumeration elements()
Returns an Enumeration of the components of this list.

Returns:
an Enumeration of the components of this list.
 o toString
 public String toString()
Returns a String representation of the list.

Returns:
a String representation of the list.
Overrides:
toString in class Object
 o main
 public static void main(String argv[])
Runs test cases on the the List class. Prints summary information on basic operations and halts with an error (and a stack trace) if any of the tests fail.


All Packages  Class Hierarchy  This Package  Previous  Next  Index