All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class DataStructures.LinkedListItr

java.lang.Object
    |
    +----DataStructures.LinkedListItr

public class LinkedListItr
extends Object
implements ListItr
Linked list implementation of the list iterator using a header node.

See Also:
LinkedList

Variable Index

 o current
Current position.
 o theList
List header.

Constructor Index

 o LinkedListItr(LinkedList)
Construct the list.
 o LinkedListItr(List)
Construct the list.

Method Index

 o advance()
Advance the current position to the next node in the list.
 o copy(LinkedList, LinkedList)
 o find(Object)
Set the current position to the first node containing an item.
 o first()
Set the current position to the first node in the list.
 o insert(Object)
Insert after the current position.
 o isInList()
Test if the current position references a valid list item.
 o main(String[])
 o print(LinkedList)
 o remove(Object)
Remove the first occurrence of an item.
 o removeNext()
Remove the item after the current position.
 o retrieve()
Return the item stored in the current position.
 o zeroth()
Set the current position to the header node.

Variables

 o theList
protected LinkedList theList
List header.

 o current
protected ListNode current
Current position.

Constructors

 o LinkedListItr
public LinkedListItr(List anyList) throws ClassCastException
Construct the list.

Parameters:
anyList - a LinkedList object to which this iterator is permanently bound. This constructor is provided for convenience. If anyList is not a LinkedList object, a ClassCastException will result.
 o LinkedListItr
public LinkedListItr(LinkedList anyList)
Construct the list. As a result of the construction, the current position is the first item, unless the list is empty, in which case the current position is the zeroth item.

Parameters:
anyList - a LinkedList object to which this iterator is permanently bound.

Methods

 o insert
public void insert(Object x) throws ItemNotFound
Insert after the current position. current is set to the inserted node on success.

Parameters:
x - the item to insert.
Throws: ItemNotFound
if the current position is null.
 o find
public boolean find(Object x)
Set the current position to the first node containing an item. current is unchanged if x is not found.

Parameters:
x - the item to search for.
Returns:
true if the item is found, false otherwise.
 o remove
public void remove(Object x) throws ItemNotFound
Remove the first occurrence of an item. current is set to the first node on success; remains unchanged otherwise.

Parameters:
x - the item to remove.
Throws: ItemNotFound
if the item is not found.
 o removeNext
public boolean removeNext()
Remove the item after the current position. current is unchanged.

Returns:
true if successful false otherwise.
 o isInList
public boolean isInList()
Test if the current position references a valid list item.

Returns:
true if the current position is not null and is not referencing the header node.
 o retrieve
public Object retrieve()
Return the item stored in the current position.

Returns:
the stored item or null if the current position is not in the list.
 o zeroth
public void zeroth()
Set the current position to the header node.

 o first
public void first()
Set the current position to the first node in the list. This operation is valid for empty lists.

 o advance
public void advance()
Advance the current position to the next node in the list. If the current position is null, then do nothing. No exceptions are thrown by this routine because in the most common use (inside a for loop), this would require the programmer to add an unnecessary try/catch block.

 o copy
public static void copy(LinkedList lhs,
                        LinkedList rhs)
 o print
public static void print(LinkedList theList)
 o main
public static void main(String[] args)

All Packages  Class Hierarchy  This Package  Previous  Next  Index