Quick Index
Concepts


The "remove" operation is basically the inverse of the "insert" operation.

Note that we do not need to worry about capacity for remove.

Shift to the left all elements that are to the right of "index".

Valid "index" values are from 0 to "size - 1".
remove(index)
The index that we want to remove.
We need to shift to the left all elements that are to the right of "index".

The remove position is "filled" with a shifted element from the right.
Try to come up with an algorithm on your own.


This algorithm will be basically the inverse
of the 'insert' algorithm

Hint: be careful not to "wipe out"
existing data if you move data around.


removeAll


Remove all can be done easily and efficiently -- Big O(1).

All that needs to be done is to "reset" the DynamicArray -- i.e., reset the instance variables of "size" to 0 and reinitialize the fixed array using the "initialCapacity" ivar.

More Examples


Also see this...

Walk-Through



The other remove methods behave with a similar pattern.