This question evaluates proficiency in data structures and generic collection implementation, specifically list operations, iterator semantics, and higher-order map functions.
You are asked to implement a simple generic list type without using any built-in collection classes (e.g., no ArrayList, LinkedList, Vector, etc.). You may use primitive arrays / custom nodes.
Design and implement MyList<T> with at least the following operations:
void add(T value)
T get(int index)
void set(int index, T value)
(or return a new value)
T remove(int index)
int size()
Requirements:
Extend MyList<T> so it is iterable.
hasNext()
and
next()
; optionally
remove()
if you support it).
0
to
size()-1
.
Add a map-style higher-order function:
MyList<R> map(Function<T, R> f)
(or equivalent in your language)
It should:
f
to each element in order
MyList<R>
containing the mapped results
null
unless you choose to forbid it (but document your choice).