Sign in to follow this  

Ron Penton Data Structures book

This topic is 4712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
To add to the subject, I agree with Yann, it is all in how you use the array that matters...

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."

Share this post


Link to post
Share on other sites
Quote:
Original post by Raisor
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."


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.

Share this post


Link to post
Share on other sites

This topic is 4712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this