|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstructure5.AbstractStructure<E>
structure5.AbstractList<E>
structure5.CircularList<E>
public class CircularList<E>
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 Node<E> |
tail
A reference to tail of list. |
Constructor Summary | |
---|---|
CircularList()
Construct an empty circular list. |
Method Summary | |
---|---|
void |
add(E value)
Add an element to head of circular list. |
void |
add(int i,
E o)
Insert value at location. |
void |
addFirst(E value)
Add an element to head of list. |
void |
addLast(E value)
Add a value to tail of circular list. |
void |
clear()
Remove elements of list. |
boolean |
contains(E value)
Check if a list contains an element. |
E |
get(int i)
Get value at location i. |
E |
getFirst()
Determine if a list is empty. |
E |
getLast()
Peek at last element of list. |
protected Node<E> |
getTail()
Accessor method for tail field |
int |
indexOf(E value)
Determine first location of a value in list. |
boolean |
isEmpty()
Determine if a list is empty. |
java.util.Iterator<E> |
iterator()
Construct an iterator over elements of list. |
int |
lastIndexOf(E value)
Determine last location of a value in list. |
E |
remove(E value)
Remove a value from a list. |
E |
remove(int i)
Remove and return value at location i. |
E |
removeFirst()
Remove a value from head of list. |
E |
removeLast()
Remove a value from tail of list. |
E |
set(int i,
E o)
Set value stored at location i to object o, returning old value. |
int |
size()
Determine size of list. |
java.lang.String |
toString()
Generate a string representation of list. |
Methods inherited from class structure5.AbstractList |
---|
get, remove |
Methods inherited from class structure5.AbstractStructure |
---|
elements, hashCode, values |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure5.Structure |
---|
elements, values |
Field Detail |
---|
protected Node<E> tail
protected int count
Constructor Detail |
---|
public CircularList()
Method Detail |
---|
public void add(E value)
add
in interface List<E>
add
in interface Structure<E>
add
in class AbstractList<E>
value
- value to be added to list.AbstractList.addLast(E)
public void addFirst(E value)
addFirst
in interface List<E>
addFirst
in class AbstractList<E>
value
- value added to head of list.public void addLast(E value)
addLast
in interface List<E>
addLast
in class AbstractList<E>
value
- value to be added.public E getFirst()
getFirst
in interface List<E>
getFirst
in class AbstractList<E>
public E getLast()
getLast
in interface List<E>
getLast
in class AbstractList<E>
public E removeFirst()
removeFirst
in interface List<E>
removeFirst
in class AbstractList<E>
public E removeLast()
removeLast
in interface List<E>
removeLast
in class AbstractList<E>
public boolean contains(E value)
contains
in interface List<E>
contains
in interface Structure<E>
contains
in class AbstractList<E>
value
- value sought.
public E remove(E value)
value
- value sought.
public int size()
public E get(int i)
i
- position of value to be retrieved.
protected Node<E> getTail()
public E set(int i, E o)
i
- location of entry to be changed.o
- new value
public void add(int i, E o)
i
- index of this new valueo
- value to be storedpublic E remove(int i)
i
- position of value to be retrieved.
public int indexOf(E value)
value
- value sought.
public int lastIndexOf(E value)
value
- value sought.
public java.util.Iterator<E> iterator()
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public boolean isEmpty()
isEmpty
in interface List<E>
isEmpty
in interface Structure<E>
isEmpty
in class AbstractList<E>
public void clear()
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 |