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.
-
MyList()
- Construct empty list.
-
advance()
- Move the internal pointer to the next element in the list.
-
atEnd()
- Are we beyond the last element of the list?
-
getCurrent()
- Return the element of the lists the internal pointer points to.
-
insertBack(Object)
- Insert an object at the end of the list.
-
insertFront(Object)
- Insert an object at the beginning of the list.
-
isEmpty()
- Test if list is empty.
-
removeFirst()
- Get the first element and remove it from the list.
-
reset()
- Set the internal pointer to the beginning of the list.
-
toString()
- Convert to string.
MyList
public MyList()
- Construct empty list.
insertFront
public void insertFront(Object o)
- Insert an object at the beginning of the list.
- Parameters:
- o - object to be inserted.
insertBack
public void insertBack(Object o)
- Insert an object at the end of the list.
- Parameters:
- o - object to be inserted.
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.
isEmpty
public boolean isEmpty()
- Test if list is empty.
- Returns:
- true if and only if the list is empty.
reset
public void reset()
- Set the internal pointer to the beginning of the list.
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.
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.
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.
toString
public String toString()
- Convert to string.
- Returns:
- string.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index