All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class util.MyList

java.lang.Object
   |
   +----util.MyList

public class MyList
extends Object
implements ListWithPointer
My own implementation of a linked list.


Constructor Index

 o MyList()
Construct empty list.

Method Index

 o advance()
Move the internal pointer to the next element in the list.
 o atEnd()
Are we beyond the last element of the list?
 o getCurrent()
Return the element of the lists the internal pointer points to.
 o insertBack(Object)
Insert an object at the end of the list.
 o insertFront(Object)
Insert an object at the beginning of the list.
 o isEmpty()
Test if list is empty.
 o removeFirst()
Get the first element and remove it from the list.
 o reset()
Set the internal pointer to the beginning of the list.
 o toString()
Convert to string.

Constructors

 o MyList
 public MyList()
Construct empty list.

Methods

 o insertFront
 public void insertFront(Object o)
Insert an object at the beginning of the list.

Parameters:
o - object to be inserted.
 o insertBack
 public void insertBack(Object o)
Insert an object at the end of the list.

Parameters:
o - object to be inserted.
 o removeFirst
 public Object removeFirst()
Get the first element and remove it from the list. The pointer to the current element is set to the first element of the list after the deletion.

Returns:
the remove element or null if the list is empty.
 o isEmpty
 public boolean isEmpty()
Test if list is empty.

Returns:
true if and only if the list is empty.
 o reset
 public void reset()
Set the internal pointer to the beginning of the list.

 o getCurrent
 public Object getCurrent() throws ListException
Return the element of the lists the internal pointer points to. Throw exception if the list is empty or the pointer is beyond the last element.

Returns:
the current list element.
Throws: ListException
if the pointer is invalid.
 o advance
 public void advance() throws ListException
Move the internal pointer to the next element in the list.

Throws: ListException
if the list is empty or the pointer is beyond the last element.
 o atEnd
 public boolean atEnd()
Are we beyond the last element of the list?

Returns:
true if and only if the pointer is beyond the last element.
 o toString
 public String toString()
Convert to string.

Returns:
string.
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index