44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
|
#include <iostream>
|
||
|
|
||
|
|
||
|
int *** create3DArray (int x, int y, int z) {
|
||
|
int*** pArray3D = new int**[x];
|
||
|
for (int i = 0; i < x; ++i) {
|
||
|
int **pArray2D = new int*[y];
|
||
|
for (int j = 0; j < y; ++j) {
|
||
|
int *pArray = new int[z];
|
||
|
pArray2D[j] = pArray;
|
||
|
//free(pArray);
|
||
|
}
|
||
|
pArray3D[i] = pArray2D;
|
||
|
//free(pArray2D);
|
||
|
}
|
||
|
return pArray3D;
|
||
|
}
|
||
|
|
||
|
void initialize3DArray(int ***ppp, int x, int y, int z) {
|
||
|
int counter = 0;
|
||
|
for (int i = 0; i < x; ++i) {
|
||
|
for (int j = 0; j < y; ++j) {
|
||
|
for (int k = 0; k < z; ++k) {
|
||
|
ppp[i][j][k] = ++counter;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void traverse3DArrayOffsets(int ***ppp, int x, int y, int z) {
|
||
|
char *dashes = "---------";
|
||
|
for (int i = 0; i < x; ++i) {
|
||
|
std::cout << dashes << " Table " << (i + 1) << " " << dashes << std::endl;
|
||
|
for (int j = 0; j < y; ++j) {
|
||
|
for (int k = 0; k < z; ++k) {
|
||
|
std::cout << *(ppp[i][j] + k) << ", ";
|
||
|
}
|
||
|
std::cout << std::endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//std::string print3DArray()
|