|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--structure.AbstractStructure
|
+--structure.AbstractList
|
+--structure.SinglyLinkedList
An implementation of lists using singly linked elements, similar to that of java.util.LinkedList.
This class is a basic implementation of the List interface.
Operations accessing or modifying the head of the list execute in constant
time.
Operations accessing or modifying the tail of the list execute in a time
proportional to the length of the list.
Singly linked lists are space-efficient, but tail-related operations may be more
costly than with doubly linked lists.
Example usage: To place a copy of every unique parameter passed to a program into a SinglyLinkedList, we would use the following:
public static void main(String[]arguments) {SinglyLinkedListargList = newSinglyLinkedList(); for (int i = 0; i < arguments.length; i++){ if (!argList.contains(arguments[i])){ argList.add(arguments[i]); } } System.out.println(argList); }
DoublyLinkedList,
CircularList| Field Summary | |
protected int |
count
The number of elements in list. |
protected SinglyLinkedListElement |
head
The head of the list. |
| Constructor Summary | |
SinglyLinkedList()
Construct an empty list. |
|
| Method Summary | |
void |
add(int i,
java.lang.Object o)
Insert value at location. |
void |
add(java.lang.Object value)
Add an object to tail of list. |
void |
addFirst(java.lang.Object value)
Add a value to head of list. |
void |
addLast(java.lang.Object value)
Add a value to tail of list. |
void |
clear()
Remove all values from list. |
boolean |
contains(java.lang.Object value)
Check to see if a value is in list. |
java.lang.Object |
get(int i)
Get value at location i. |
java.lang.Object |
getFirst()
Fetch first element of list. |
java.lang.Object |
getLast()
Fetch last element of list. |
int |
indexOf(java.lang.Object value)
Determine first location of a value in list. |
java.util.Iterator |
iterator()
Returns an iterator traversing list from head to tail. |
int |
lastIndexOf(java.lang.Object value)
Determine last location of a value in list. |
java.lang.Object |
remove(int i)
Remove and return value at location i. |
java.lang.Object |
remove(java.lang.Object value)
Remove a value from list. |
java.lang.Object |
removeFirst()
Remove a value from first element of list. |
java.lang.Object |
removeLast()
Remove last value from list. |
java.lang.Object |
set(int i,
java.lang.Object o)
Set value stored at location i to object o, returning old value. |
int |
size()
Determine number of elements in list. |
java.lang.String |
toString()
Construct a string representing list. |
| Methods inherited from class structure.AbstractList |
get, isEmpty, remove |
| Methods inherited from class structure.AbstractStructure |
elements, hashCode, values |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface structure.Structure |
elements, values |
| Field Detail |
protected int count
protected SinglyLinkedListElement head
| Constructor Detail |
public SinglyLinkedList()
| Method Detail |
public void add(java.lang.Object value)
add in interface Listadd in class AbstractListvalue - The value to be added to tail of list.AbstractList.addLast(java.lang.Object)public void addFirst(java.lang.Object value)
addFirst in interface ListaddFirst in class AbstractListvalue - The value to be added to head of list.public java.lang.Object removeFirst()
removeFirst in interface ListremoveFirst in class AbstractListpublic void addLast(java.lang.Object value)
addLast in interface ListaddLast in class AbstractListvalue - The value to be added to tail of list.public java.lang.Object removeLast()
removeLast in interface ListremoveLast in class AbstractListpublic java.lang.Object getFirst()
getFirst in interface ListgetFirst in class AbstractListpublic java.lang.Object getLast()
getLast in interface ListgetLast in class AbstractListpublic boolean contains(java.lang.Object value)
contains in interface Listcontains in class AbstractListvalue - The value sought.
public java.lang.Object remove(java.lang.Object value)
value - The value to be removed.
public int size()
public void clear()
public java.lang.Object get(int i)
i - position of value to be retrieved.
public java.lang.Object set(int i,
java.lang.Object o)
i - location of entry to be changed.o - new value
public void add(int i,
java.lang.Object o)
i - index of this new valueo - value to be storedpublic java.lang.Object remove(int i)
i - position of value to be retrieved.
public int indexOf(java.lang.Object value)
value - value sought
public int lastIndexOf(java.lang.Object value)
value - value sought.
public java.util.Iterator iterator()
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||