Array support three basic operations: Index, insert, delete(erase in
STL).
Dynamic two dimension array can be implemented below: char ** p; should
be used as ragged array. Pay attention to p[1][2] and pa[1][2]. They are all
correct forms.
All ragged array should include terminate flag, so you can know the length
of each row. For C-style string ragged array, the ’NULL’ in the end of string
can be used as terminate flag directly, so ragged array is idea container for
C-style string array.
If you want to insert an element into an array, you need to copybackward from end. if erase an element from an array, copy forwardfrom erasing point.
If you have an array of big object, and you need to sort it. You can build a
array of pointer to point to each object in the array. When you sort the an
array of big object, you just move pointer instead, It is called "indirect
addressing", It can help you to avoid moving big chunk of data. If you want
to put them into STL container, you can use smart pointer, such as
unique_ptr. Don’t use auto_ptr.
reverse array can be implemented by swap, But reverse list need different
algorithm, so in STL , list<> has its own reverse member function.