Modifier and Type | Class and Description |
---|---|
class |
MyLinkedList.MyListIterator
Students don't have to implement Java ListIterator<T> interface for this inner class.
|
Constructor and Description |
---|
MyLinkedList()
This is the constructor that simply set head to null
|
MyLinkedList(MyLinkedList<T> a)
This is the copy constructor
|
Modifier and Type | Method and Description |
---|---|
void |
add(int at,
T item)
Add (insert) item to the ith position of this MyList.
|
void |
add(T item)
Add item to the end of this List.
|
T |
get(int at)
Get the element at index i
|
int |
indexOf(java.lang.Object data)
Find the index of the input item in this MyList.
|
java.util.Iterator<T> |
iterator() |
java.util.ListIterator<T> |
listIterator() |
T |
remove(int at)
Remove the item at the ith position from this MyArrayList.
|
void |
reverse()
This method reverses the contents of the list.
|
T |
set(int at,
T data)
Replace the element at i with new one provided by the parameter item.
|
int |
size() |
java.lang.Object[] |
toArray()
This method return an Object array of the same size that contains every element
in this MyList;
|
<K> K[] |
toArray(K[] a)
Returns an array that contains every element in this MyList.
|
java.lang.String |
toString()
Override toString method so it will return a String started and ended by [ and ],
respectively, in which all elements' results of their own toString() will be
concatenated according to their order in the list.
|
public MyLinkedList()
public MyLinkedList(MyLinkedList<T> a)
a
- is a MyLinkedList to be copied.public int size()
size
in interface MyList<T>
MyList.size()
public T get(int at)
MyList
get
in interface MyList<T>
at
- is an int.MyList.get(int)
public int indexOf(java.lang.Object data)
MyList
indexOf
in interface MyList<T>
data
- is an Object.MyList.indexOf(java.lang.Object)
public T set(int at, T data)
MyList
set
in interface MyList<T>
at
- is an int.data
- is a T.MyList.set(int, java.lang.Object)
public void add(T item)
MyList
add
in interface MyList<T>
item
- is a T.MyList.add(java.lang.Object)
public void add(int at, T item)
MyList
add
in interface MyList<T>
at
- is an int.item
- is a T.MyList.add(int, java.lang.Object)
public T remove(int at)
MyList
remove
in interface MyList<T>
at
- is an int.MyList.remove(int)
public java.lang.Object[] toArray()
MyList
toArray
in interface MyList<T>
MyList.toArray()
public <K> K[] toArray(K[] a)
MyList
public java.lang.String toString()
MyList
public void reverse()
public java.util.ListIterator<T> listIterator()