|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectstructure.AbstractStructure<ELTTYPE>
structure.AbstractList<ELTTYPE>
structure.SinglyLinkedList<ELTTYPE>
public class SinglyLinkedList<ELTTYPE>
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| Constructor Summary | |
|---|---|
SinglyLinkedList()
Construct an empty list. |
|
| Method Summary | |
|---|---|
void |
add(ELTTYPE value)
Add an object to tail of list. |
void |
add(int i,
ELTTYPE o)
Insert value at location. |
void |
addFirst(ELTTYPE value)
Add a value to head of list. |
void |
addLast(ELTTYPE value)
Add a value to tail of list. |
void |
clear()
Remove all values from list. |
boolean |
contains(ELTTYPE value)
Check to see if a value is in list. |
ELTTYPE |
get(int i)
Get value at location i. |
ELTTYPE |
getFirst()
Fetch first element of list. |
ELTTYPE |
getLast()
Fetch last element of list. |
int |
indexOf(ELTTYPE value)
Determine first location of a value in list. |
java.util.Iterator<ELTTYPE> |
iterator()
Returns an iterator traversing list from head to tail. |
int |
lastIndexOf(ELTTYPE value)
Determine last location of a value in list. |
ELTTYPE |
remove(ELTTYPE value)
Remove a value from list. |
ELTTYPE |
remove(int i)
Remove and return value at location i. |
ELTTYPE |
removeFirst()
Remove a value from first element of list. |
ELTTYPE |
removeLast()
Remove last value from list. |
ELTTYPE |
set(int i,
ELTTYPE 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 |
|---|
equals, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface structure.Structure |
|---|
elements, values |
| Constructor Detail |
|---|
public SinglyLinkedList()
| Method Detail |
|---|
public void add(ELTTYPE value)
add in interface List<ELTTYPE>add in interface Structure<ELTTYPE>add in class AbstractList<ELTTYPE>value - The value to be added to tail of list.AbstractList.addLast(ELTTYPE)public void addFirst(ELTTYPE value)
addFirst in interface List<ELTTYPE>addFirst in class AbstractList<ELTTYPE>value - The value to be added to head of list.public ELTTYPE removeFirst()
removeFirst in interface List<ELTTYPE>removeFirst in class AbstractList<ELTTYPE>public void addLast(ELTTYPE value)
addLast in interface List<ELTTYPE>addLast in class AbstractList<ELTTYPE>value - The value to be added to tail of list.public ELTTYPE removeLast()
removeLast in interface List<ELTTYPE>removeLast in class AbstractList<ELTTYPE>public ELTTYPE getFirst()
getFirst in interface List<ELTTYPE>getFirst in class AbstractList<ELTTYPE>public ELTTYPE getLast()
getLast in interface List<ELTTYPE>getLast in class AbstractList<ELTTYPE>public boolean contains(ELTTYPE value)
contains in interface List<ELTTYPE>contains in interface Structure<ELTTYPE>contains in class AbstractList<ELTTYPE>value - The value sought.
public ELTTYPE remove(ELTTYPE value)
value - The value to be removed.
public int size()
public void clear()
public ELTTYPE get(int i)
i - position of value to be retrieved.
public ELTTYPE set(int i,
ELTTYPE o)
i - location of entry to be changed.o - new value
public void add(int i,
ELTTYPE o)
i - index of this new valueo - value to be storedpublic ELTTYPE remove(int i)
i - position of value to be retrieved.
public int indexOf(ELTTYPE value)
value - value sought
public int lastIndexOf(ELTTYPE value)
value - value sought.
public java.util.Iterator<ELTTYPE> iterator()
AbstractIterator,
Iterator,
Enumeration,
Structure.elements()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 | |||||||