Setting by Index
set does the opposite of get. Instead of reading the value at an index, it overwrites that value. Here it is:
public void set(int index, T value) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
node(index).value = value;
}
Reaching the node takes . The assignment itself is . In DynamicArray, this was because it could index directly into the array in constant time.
This is why node returns a Node<T> instead of a T value: to set the value, we need to reach the node and then overwrite its value field.