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
-
current
- Current position.
-
theList
- List header.
-
LinkedListItr(LinkedList)
- Construct the list.
-
LinkedListItr(List)
- Construct the list.
-
advance()
- Advance the current position to the next node in the list.
-
copy(LinkedList, LinkedList)
-
-
find(Object)
- Set the current position to the first node containing an item.
-
first()
- Set the current position to the first node in the list.
-
insert(Object)
- Insert after the current position.
-
isInList()
- Test if the current position references a valid list item.
-
main(String[])
-
-
print(LinkedList)
-
-
remove(Object)
- Remove the first occurrence of an item.
-
removeNext()
- Remove the item after the current position.
-
retrieve()
- Return the item stored in the current position.
-
zeroth()
- Set the current position to the header node.
theList
protected LinkedList theList
- List header.
current
protected ListNode current
- Current position.
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.
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.
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.
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.
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.
removeNext
public boolean removeNext()
- Remove the item after the current position.
current is unchanged.
- Returns:
- true if successful false otherwise.
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.
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.
zeroth
public void zeroth()
- Set the current position to the header node.
first
public void first()
- Set the current position to the first node in the list.
This operation is valid for empty lists.
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.
copy
public static void copy(LinkedList lhs,
LinkedList rhs)
print
public static void print(LinkedList theList)
main
public static void main(String[] args)
All Packages Class Hierarchy This Package Previous Next Index