I have to write a code in which i want to use 3 dimensional array but i am reaaly confused that how 2 dimen array is indexed. 2x2 array can easily be indexed 00 01 10 11. so how a 3 dimen one can be indexed?

5 Years
Discussion Span
Last Post by Ancient Dragon

The indexing works the same way since it's nothing more than an array of 2D arrays. If you add another dimension of 2, duplicate what you posted each with an index of 0 and 1: 000 001 010 011 100 101 110 111.


Lets pretend you attend a 12 cinima movie threater. Inside one of the 12 cinimas you will find several rows of seats, each row contains any number of seats. That is a 2d array of seats

Now you can consider the entire cinima threater as a 3d array -- the first dimension represents each of the 12 cinimas, and inside each cinima is a 2d array of seats

So if you represent all the seats liks this

int const NumberCinimas = 12;
int const NumberRows = 15;
int const NumberSeatsPerRow = 20;

int Seats[NumberCinimas][NumberRows][NumberSeatsPerRow];

To assign a seat to someone you will need to know the cinima he wants to watch, and an empty seat in the desired row. So I can buy a ticket for cinima #3, row 15, seat 4

Seats[3][15][4] = AncientDragon;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.