Wrong idea. Arrays are based on using of continuous memory chunks and are not suitable for removing. If want to do this, you will need to reallocate the memory and, essentially, rewrite some part of original array or all of it. This is an inefficient operation which would defeat the purpose of the array's efficiency. Therefore, you should better use some other data structure suitable for deletion, such as vector or linked list, as with the
template classes vector
or
list
found in the standard C++ library:
http://www.cplusplus.com/reference/vector/vector[
^],
http://www.cplusplus.com/reference/list/list[
^].
For example, "2D arrays" can be represented as vectors of vectors, lists of lists, vectors of list or lists of vectors, depending on your requirements. In fact, that will make the "jagged arrays", which would be fine for your purposes. See also:
http://en.wikipedia.org/wiki/Jagged_array[
^].
I also want to point out that, due the nature of C and C++ arrays, "1D array" and "2D array" is exactly the same thing. The multi-index access to the array elements is nothing but
syntactic sugar:
http://en.wikipedia.org/wiki/Syntactic_sugar[
^].
—SA