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)
SortedList
remove
in interface SortedList<T extends java.lang.Comparable<? super T>>
targetItem
- element to be removed from this list, if presentpublic T remove(int index)
SortedList
remove
in interface SortedList<T extends java.lang.Comparable<? super T>>
index
- index of the element to be removedpublic int indexOf(T targetItem)
SortedList
indexOf
in interface SortedList<T extends java.lang.Comparable<? super T>>
targetItem
- itempublic void clear()
SortedList
clear
in interface SortedList<T extends java.lang.Comparable<? super T>>
public T get(int position)
SortedList
get
in interface SortedList<T extends java.lang.Comparable<? super T>>
position
- specified positionpublic boolean contains(T targetItem)
SortedList
contains
in interface SortedList<T extends java.lang.Comparable<? super T>>
targetItem
- specified elementpublic int size()
SortedList
size
in interface SortedList<T extends java.lang.Comparable<? super T>>
public boolean isEmpty()
SortedList
isEmpty
in interface SortedList<T extends java.lang.Comparable<? super T>>
public java.lang.Object[] toArray()
SortedList
toArray
in interface SortedList<T extends java.lang.Comparable<? super T>>
public java.util.Iterator<T> iterator()
SortedList
public static void main(java.lang.String[] args)