Ron Penton Data Structures book
Can someone explain why Penton treats a 2D array such as:
a[4][3] like I would treat a[3][4].
At first I thought it was a mistake (page 115) but he does this multiple times throughout the chapter (page 124).
could you be a little more clearer?
maybe with some pseudocode or something?
cuz obviously you and him treat rows and columns differently.
maybe with some pseudocode or something?
cuz obviously you and him treat rows and columns differently.
Sorry!
He shows this after "a[4][3] = 10" :
Shouldn't this be a[3][4]? He is writing his own 2DArray class so perhaps this is how his implementation works but I just don't see it. If someone with the book could explain what he is doing here I would appreciate it.
And on page 124 he draws a 4x5 array with 5 rows and 4 columns. Just backwards to how I'm used to thinking about it.
He shows this after "a[4][3] = 10" :
Shouldn't this be a[3][4]? He is writing his own 2DArray class so perhaps this is how his implementation works but I just don't see it. If someone with the book could explain what he is doing here I would appreciate it.
And on page 124 he draws a 4x5 array with 5 rows and 4 columns. Just backwards to how I'm used to thinking about it.
HughG: it doesn't matter which order you take, as long as you are consistent with your choice. A two dimensional array is just that: an abstract field of 2D data. The attribution of rows and columns to indices is purely arbitrary, there is no fixed notation of "this is X, and this is Y". A[x][y] is just as valid as a[y][x], as long as you don't mix both. It's a matter of preference.
It starts to matter when treating the 2D array as a matrix (the swapping of the index axes is called 'transposing' there), but in the simple case of a two dimensional grid, just use whatever notation you prefer and stick with it.
It starts to matter when treating the 2D array as a matrix (the swapping of the index axes is called 'transposing' there), but in the simple case of a two dimensional grid, just use whatever notation you prefer and stick with it.
To add to the subject, I agree with Yann, it is all in how you use the array that matters...
ROFLMFAO!!!!! This is the funniest quote I have ever heard! Has replaced my favorite from Einstein... "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
Quote:Original post by Luctus
... In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move ...
ROFLMFAO!!!!! This is the funniest quote I have ever heard! Has replaced my favorite from Einstein... "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
Quote:Original post by RaisorQuote:Original post by Luctus
... In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move ...
ROFLMFAO!!!!! This is the funniest quote I have ever heard! Has replaced my favorite from Einstein... "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
Yeah, I agree with you there. I told it to my friend one time and he was just like "...okay", I thought it was hilareous but no one else seemed to really get anything out of it.
It has to be a misprint. Your right about the picture, it should correspond to
a[3][4] = 10;
Because the first subscript is the number of arrays, which is the same as saying the amount of rows.
a[3][4] = 10;
Because the first subscript is the number of arrays, which is the same as saying the amount of rows.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement