|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractStructure | +--structure.AbstractList | +--structure.CircularList
An implementation of lists using circularly linked elements,
similar to that of java.util.LinkedList
.
This class is an implementation of the List
interface.
Operations accessing or modifying either the head or the tail of
the list execute in constant time.
Circular lists are as space-efficient as singly linked lists,
but tail-related operations are less costly.
Example usage: To place a copy of every unique parameter passed to a program into a CircularList, we would use the following:
public static void main(String[]
arguments) {CircularList
argList = newCircularList()
; for (int i = 0; i < arguments.length; i++){ if (!argList.contains(arguments[i])
){ argList.add(arguments[i])
; } } System.out.println(argList); }
SinglyLinkedList
,
DoublyLinkedList
Field Summary | |
protected int |
count
Number of elements within circular list. |
protected SinglyLinkedListElement |
tail
A reference to tail of list. |
Constructor Summary | |
CircularList()
Construct an empty circular list. |
Method Summary | |
void |
add(int i,
Object o)
Insert value at location. |
void |
add(Object value)
Add an element to head of circular list. |
void |
addFirst(Object value)
Add an element to head of list. |
void |
addLast(Object value)
Add a value to tail of circular list. |
void |
clear()
Remove elements of list. |
boolean |
contains(Object value)
Check if a list contains an element. |
Object |
get(int i)
Get value at location i. |
Object |
getFirst()
Determine if a list is empty. |
Object |
getLast()
Peek at last element of list. |
protected SinglyLinkedListElement |
getTail()
Accessor method for tail field |
int |
indexOf(Object value)
Determine first location of a value in list. |
boolean |
isEmpty()
Determine if a list is empty. |
Iterator |
iterator()
Construct an iterator over elements of list. |
int |
lastIndexOf(Object value)
Determine last location of a value in list. |
Object |
remove(int i)
Remove and return value at location i. |
Object |
remove(Object value)
Remove a value from a list. |
Object |
removeFirst()
Remove a value from head of list. |
Object |
removeLast()
Remove a value from tail of list. |
Object |
set(int i,
Object o)
Set value stored at location i to object o, returning old value. |
int |
size()
Determine size of list. |
String |
toString()
Generate a string representation of list. |
Methods inherited from class structure.AbstractList |
get, remove |
Methods inherited from class structure.AbstractStructure |
elements, hashCode, values |
Methods inherited from class java.lang.Object |
|
Methods inherited from interface structure.Structure |
elements, values |
Field Detail |
protected SinglyLinkedListElement tail
protected int count
Constructor Detail |
public CircularList()
Method Detail |
public void add(Object value)
add
in class AbstractList
value
- value to be added to list.public void addFirst(Object value)
addFirst
in class AbstractList
value
- value added to head of list.public void addLast(Object value)
addLast
in class AbstractList
value
- value to be added.public Object getFirst()
getFirst
in class AbstractList
public Object getLast()
getLast
in class AbstractList
public Object removeFirst()
removeFirst
in class AbstractList
public Object removeLast()
removeLast
in class AbstractList
public boolean contains(Object value)
contains
in class AbstractList
value
- value sought.public Object remove(Object value)
value
- value sought.public int size()
public Object get(int i)
i
- position of value to be retrieved.protected SinglyLinkedListElement getTail()
public Object set(int i, Object o)
i
- location of entry to be changed.o
- new valuepublic void add(int i, Object o)
i
- index of this new valueo
- value to be storedpublic Object remove(int i)
i
- position of value to be retrieved.public int indexOf(Object value)
value
- value sought.public int lastIndexOf(Object value)
value
- value sought.public Iterator iterator()
public boolean isEmpty()
isEmpty
in class AbstractList
public void clear()
public String toString()
toString
in class Object
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |