T
- can be any class.public class MySLinkedList<T> extends java.lang.Object implements MyList<T>, java.lang.Cloneable
Constructor and Description |
---|
MySLinkedList()
This is the default constructor that simply set head to null
|
MySLinkedList(MySLinkedList<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.
|
java.lang.Object |
clone() |
boolean |
equals(java.lang.Object o)
The equals method of T item will be used.
|
T |
get(int at)
Get the element at index i
|
int |
indexOf(java.lang.Object o)
Find the index of the input item in this MyList.
|
java.util.Iterator<T> |
iterator() |
T |
remove(int at)
Remove the item at the ith position from this MyArrayList.
|
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 MySLinkedList()
public MySLinkedList(MySLinkedList<T> a)
a
- is a MySLinkedList of the same type to be copied.public java.lang.Object clone()
clone
in class java.lang.Object
Object.clone()
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 o)
MyList
indexOf
in interface MyList<T>
o
- 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
toArray
in interface MyList<T>
K
- is any typea
- is the specific array to receive the elementMyList.toArray(Object[])
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public java.lang.String toString()
MyList