Write SinglyList containing a generic class MyLinkedList<E>: a singly linked list with head, tail and size, and the methods
addFirst, addLast, add(index, e), get(index), set(index, e) (returns the old element), remove(index) (returns the removed element), indexOf, lastIndexOf, contains, size, toString.
An illegal index throws an IndexOutOfBoundsException with the message index 9, size 3.
main drives a list of strings with the commands add x, addFirst x, addAt i x, get i, set i x, remove i, indexOf x, lastIndexOf x, contains x, print, catching the exception. toString also shows the first and last elements, to verify head and tail. For the input
add b
add c
addFirst a
print
addAt 1 x
addAt 4 z
print
get 4
set 1 y
remove 0
remove 3
print
add b
indexOf b
lastIndexOf b
contains q
get 9
the program prints
3 element(s): [a, b, c] first a, last c
5 element(s): [a, x, b, c, z] first a, last z
get: z
set replaced x
removed a
removed z
3 element(s): [y, b, c] first y, last c
indexOf: 1
lastIndexOf: 3
contains: false
Refused: index 9, size 4
Final: [y, b, c, b] first y, last b