I. Double pointer Method
A double pointer is a pointer like a pointer. For example, you can declare an array and release the space of an array as follows:
// Declare a two-dimensional dynamic array with double pointers <br/> int ** arr = new int * [X]; // understand the meaning of double pointers, pointer-> array pointer-> two-dimensional array <br/> for (INT I = 0; I <X; ++ I) <br/> arr [I] = new int [y]; // it can be understood that an array is opened on a single bit of a one-dimensional array, it also forms a two-dimensional array </P> <p> // use Delete to release space <br/> for (INT m = 0; m <X; m ++) <br/> Delete [] P [m]; <br/> Delete [] P; <br/>
Ii. STL Vector
The declaration method is as follows:
// Declare an array of M * n with a vector <br/> vector <int> vecarr (M, vector <int> (n )); // note> there must be spaces between them, otherwise it will be misjudged as> operator <br/> for (INT I = 0; I <m; I ++) <br/> for (j = 0; j <n; j ++) <br/> vecarr [I] [J] = I * J; </P> <p> // declare an I * j * K 3D array <br/> vector <int> vecant (m, vector <vector <int> (n, vector <int> (l); <br/> for (INT I = 0; I <m; I ++) <br/> for (Int J = 0; j <n; j ++) <br/> for (k = 0; k <L; k ++) <br/> vecint [I] [J] [k] = I + J + K;