T - The type of data that the list stores.public class CarlSortedList<T extends java.lang.Comparable<? super T>> extends java.lang.Object implements SortedList<T>
| Constructor and Description |
|---|
CarlSortedList()
Default constructor: creates an empty list.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T newItem)
Adds newItem in sorted order, and shifts each item at or beyond that
index to the next higher index.
|
void |
clear()
Removes all of the elements from this list.
|
boolean |
contains(T targetItem)
Returns true if this list contains the specified element.
|
T |
get(int position)
Returns the element at the specified position in this list.
|
int |
indexOf(T targetItem)
Returns the position of the item, or -1 if item is not in the list.
|
boolean |
isEmpty()
Returns true if this list contains no elements.
|
java.util.Iterator<T> |
iterator()
Returns an iterator over the elements in this list in proper sequence.
|
static void |
main(java.lang.String[] args) |
T |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
remove(T targetItem)
Removes the specified element from this list, if it is present.
|
int |
size()
Returns the number of elements in this list.
|
java.lang.Object[] |
toArray()
Returns an array version of the list.
|
public CarlSortedList()
public void add(T newItem)
add in interface SortedList<T extends java.lang.Comparable<? super T>>newItem - element to be added to the listpublic boolean remove(T targetItem)
SortedListremove in interface SortedList<T extends java.lang.Comparable<? super T>>targetItem - element to be removed from this list, if presentpublic T remove(int index)
SortedListremove in interface SortedList<T extends java.lang.Comparable<? super T>>index - index of the element to be removedpublic int indexOf(T targetItem)
SortedListindexOf in interface SortedList<T extends java.lang.Comparable<? super T>>targetItem - itempublic void clear()
SortedListclear in interface SortedList<T extends java.lang.Comparable<? super T>>public T get(int position)
SortedListget in interface SortedList<T extends java.lang.Comparable<? super T>>position - specified positionpublic boolean contains(T targetItem)
SortedListcontains in interface SortedList<T extends java.lang.Comparable<? super T>>targetItem - specified elementpublic int size()
SortedListsize in interface SortedList<T extends java.lang.Comparable<? super T>>public boolean isEmpty()
SortedListisEmpty in interface SortedList<T extends java.lang.Comparable<? super T>>public java.lang.Object[] toArray()
SortedListtoArray in interface SortedList<T extends java.lang.Comparable<? super T>>public java.util.Iterator<T> iterator()
SortedListpublic static void main(java.lang.String[] args)