public interface ListInterface<I extends java.lang.Comparable<? super I>>
This is the interface for the List Abstract Data Type (ADT).
Please note that this
interface uses the generic type I which either implements the
Comparable interface
, or some super class of I
implements the
Comparable interface
| Modifier and Type | Method and Description |
|---|---|
void |
add(I element)
This method is called to add the specified Element to the end of the list.
|
void |
add(I element,
int index)
This method is called to add the specified Element to the list at the given index.
|
void |
addSorted(I element)
This method is called to add the specified Element to the list in sorted order.
|
ListInterface<I> |
copy()
This method will make a copy of the list and return it.
|
I |
get(int index)
This method is called to retrieve the Element at the specified index.
|
boolean |
isEmpty()
This method is called to determine if the list is empty.
|
I |
remove(int index)
This method is called to remove the Element at the specified index
|
void |
removeAll()
This method removes all Elements from the list, making the list empty.
|
I |
replace(I element,
int index)
This method is called to replace the element at the specified index with the specified
element.
|
int |
size()
This method is called to obtain the count of elements in the list.
|
ListInterface<I> copy()
int size()
boolean isEmpty()
void add(I element)
element - A reference to the element to be added to the end of the list.
All Elements being added to the list must implement the
Comparable interface.Comparablevoid add(I element, int index) throws java.lang.IndexOutOfBoundsException
element - A reference to the element to be added to the list.
All Elements being added to the list must implement the
Comparable interface.index - Indicates the position at which to add the specified Element.
java.lang.IndexOutOfBoundsException - This exception is thrown if the specified
index is invalid.Comparablevoid addSorted(I element)
element - A reference to the element being added, in sorted order,
to the list. All Elements being added to the list must implement the
Comparable interface.ComparableI get(int index) throws java.lang.IndexOutOfBoundsException
index - Indicates the position from which to retrieve the Element.
If the list currently contains n elements, using an index = i,
where 0 ≤ i < n, the get should succeed, since the index is valid.java.lang.IndexOutOfBoundsException - This exception is thrown if the specified
index is invalid.I replace(I element, int index) throws java.lang.IndexOutOfBoundsException
element - A reference to the element that will replace the current element in the list.index - Indicates the position in the list where the replacement should be made.
If the list currently contains n elements, using an index = i,
where 0 ≤ i < n, the get should succeed, since the index is valid.java.lang.IndexOutOfBoundsException - This exception is thrown if the specified
index is invalid.I remove(int index) throws java.lang.IndexOutOfBoundsException
index - Indicates the position from which to remove the Element.
If the list currently contains n elements, using an index = i,
where 0 ≤ i < n, the get should succeed, since the index is valid.java.lang.IndexOutOfBoundsException - This exception is thrown if the specified
index is invalid.void removeAll()