is there any advantage apart from the fewer memory allocations?
array = (int ***) malloc( 10 * sizeof(int **) );
array[0] = (int **) malloc( 10 * 20 * sizeof( int *) );
array[0][0] = (int *) malloc( 10 * 20 * 30 * sizeof(int) );
for ( j = 1 ; j < 20 ; ++j ) {
array[0][j] = array[0][j-1] + 30;
}
for ( i = 1 ; i < 10 ; ++i ) {
array[i] = array[i-1] + 20;
array[i][0] = array[i-1][20-1] + 30;
for ( j = 1 ; j < 20 ; ++j ) {
array[i][j] = array[i][j-1] + 30;
}
}
for (i=0; i<10; i++) {
array[i][0] = array[(i+1)*10];
}
Although that doesn't quite seem right with a 2d deference on the left and a 1d on the right.array = (int ***) malloc( 10 * sizeof(int **) );
array[0] = (int **) malloc( 10 * 20 * sizeof( int *) );
array[0][0] = (int *) malloc( 10 * 20 * 30 * sizeof(int) );
for ( j = 1 ; j < 20 ; ++j ) {
array[0][j] = array[0][j-1] + 30;
}
for ( i = 1 ; i < 10 ; ++i ) {
array[i] = array[i-1] + 20;
array[i][0] = array[i-1][20-1] + 30;
for ( j = 1 ; j < 20 ; ++j ) {
array[i][j] = array[i][j-1] + 30;
}
}
ok.png
(i*dimension)
key part, which moves along like your first 2d example. This wasn't in the code in the lecture notes, however I was forgetting that each iteration through the loop the previous iteration had already incremented along 30, so the next time was 30 along, ready for another 30 (if that makes sense).If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Does Objective C commented code increase filesize in an installed iPhone app? | 7 | 147 | |
How to get time_t value that is a week old | 6 | 168 | |
Problem to save | 10 | 166 | |
How to creat good software interface ? | 1 | 67 |
Join the community of 500,000 technology professionals and ask your questions.