|
datastructures | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.datastructures.NodeList
Realization of a List using a doubly-linked list of nodes.
Field Summary | |
protected DNode |
header
|
protected int |
numElts
|
protected DNode |
trailer
|
Constructor Summary | |
NodeList()
Constructor that creates an empty list; O(1) time |
Method Summary | |
protected DNode |
checkPosition(Position p)
Checks if position is valid for this list and converts it to DNode if it is valid; O(1) time |
Iterator |
elements()
Returns an iterator of all the elements in the list. |
Position |
first()
Returns the first position in the list; O(1) time |
Position |
insertAfter(Position p,
Object element)
Insert the given element after the given position, returning the new position; O(1) time |
Position |
insertBefore(Position p,
Object element)
Insert the given element before the given position, returning the new position; O(1) time |
Position |
insertFirst(Object element)
Insert the given element at the beginning of the list, returning the new position; O(1) time |
Position |
insertLast(Object element)
Insert the given element at the end of the list, returning the new position; O(1) time |
boolean |
isEmpty()
Returns whether the list is empty; O(1) time |
boolean |
isFirst(Position p)
Returns whether a position is the first one; O(1) time |
boolean |
isLast(Position p)
Returns whether a position is the last one; O(1) time |
Position |
last()
Returns the last position in the list; O(1) time |
Position |
next(Position p)
Returns the position after the given one; O(1) time |
Iterator |
positions()
Returns an iterator of all the nodes in the list. |
Position |
prev(Position p)
Returns the position before the given one; O(1) time |
Object |
remove(Position p)
Remove the given position from the list; O(1) time |
Object |
replace(Position p,
Object element)
Replace the element at the given position with the new element and return the old element; O(1) time |
int |
size()
Returns the number of elements in the list; O(1) time |
void |
swapElements(Position a,
Position b)
Swap the elements of two give positions; O(1) time |
String |
toString()
Returns a textual representation of the list |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int numElts
protected DNode header
protected DNode trailer
Constructor Detail |
public NodeList()
Method Detail |
protected DNode checkPosition(Position p) throws InvalidPositionException
InvalidPositionException
public int size()
size
in interface List
public boolean isEmpty()
isEmpty
in interface List
public Position first() throws EmptyListException
first
in interface List
EmptyListException
public Position last() throws EmptyListException
last
in interface List
EmptyListException
public Position prev(Position p) throws InvalidPositionException, BoundaryViolationException
prev
in interface List
InvalidPositionException
BoundaryViolationException
public Position next(Position p) throws InvalidPositionException, BoundaryViolationException
next
in interface List
InvalidPositionException
BoundaryViolationException
public Position insertBefore(Position p, Object element) throws InvalidPositionException
insertBefore
in interface List
InvalidPositionException
public Position insertAfter(Position p, Object element) throws InvalidPositionException
insertAfter
in interface List
InvalidPositionException
public Position insertFirst(Object element)
insertFirst
in interface List
public Position insertLast(Object element)
insertLast
in interface List
public Object remove(Position p) throws InvalidPositionException
remove
in interface List
InvalidPositionException
public Object replace(Position p, Object element) throws InvalidPositionException
replace
in interface List
InvalidPositionException
public Iterator positions()
positions
in interface List
public Iterator elements()
elements
in interface List
public boolean isFirst(Position p) throws InvalidPositionException
InvalidPositionException
public boolean isLast(Position p) throws InvalidPositionException
InvalidPositionException
public void swapElements(Position a, Position b) throws InvalidPositionException
InvalidPositionException
public String toString()
|
datastructures | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |