|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--DataStructures.LinkedList
A simple implementation of singly linked lists.
Lists are created empty, for example:
LinkedList list = new LinkedList();after which items can be inserted at the front of the list by
list.addFirst(item)where item is any Object.
Items can be removed from the front of the list by
list.removeFirst();which removes the first item from the list. Lists can be traversed using an iterator, for example:
for (Iterator i = list.iterator(); i.hasNext();) {
System.out.println(e.next());
{
| Constructor Summary | |
LinkedList()
Constructs an empty list. |
|
| Method Summary | |
void |
addFirst(java.lang.Object item)
Inserts an item at the front of the list. |
boolean |
contains(java.lang.Object item)
Tests whether an item is present in the list. |
boolean |
equals(java.lang.Object other)
Implements the equals method. |
java.lang.Object |
firstItem()
Returns the first item in the list. |
boolean |
isEmpty()
Tests if the list is empty. |
java.util.Iterator |
iterator()
Iterates over the items in the list. |
void |
removeFirst()
Removes the first item from the list. |
void |
reverse()
Reverses the list. |
int |
size()
Returns the length of the list |
java.lang.String |
toString()
Converts the list to a string. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public LinkedList()
| Method Detail |
public boolean isEmpty()
public int size()
public void addFirst(java.lang.Object item)
item - the Object to be inserted.public java.lang.Object firstItem()
java.util.NoSuchElementException - if the list is empty.public void removeFirst()
java.util.NoSuchElementException - if the list is empty.public boolean contains(java.lang.Object item)
item - the object to be searched for.public void reverse()
public java.util.Iterator iterator()
java.util.NoSuchElementException - if the next method
is called when there is no next elementIllegalStateException - if the next method has not
yet been called, or the remove method has already
been called after the last call to the next
method.public boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - the second linked list.public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||