# Re: Homework 7, problem 2

Stephen Edwards (edwards@CS.VT.EDU)
Mon, 19 Mar 2001 08:48:04 -0500

```Message-ID:  <3AB60E14.5175B844@cs.vt.edu>
Date:         Mon, 19 Mar 2001 08:48:04 -0500
From: Stephen Edwards <edwards@CS.VT.EDU>
Subject:      Re: Homework 7, problem 2
```

>
> On homework 7, problem 2. I am having a hard time understanding exactly
> how array elements would be stored in the case of a three dimensional
> array. Take row-major order for example.
>
> Would the elements be stored like this
>
> x[1][1][1], x[1][1][2]. . .
>
> or this
>
> x[1][1][1], x[1][2][1], x[1][3][1]. . .

The first one.

"Row major" means you cycle through all possibilities for the rightmost
index before you bump the index just to the left by one. For dimensions
greater than 2, you just extend this (i.e., the rightmost or "last" index
goes through all possiblities first, then add one to the "next-to-last"
and repeat, etc., etc.).

For "column major", you cycle through all the possibilities for the
*left*most index first, gradually moving toward the right (i.e., first
to last, instead of last to first).

-- Steve

```--
Stephen Edwards            604 McBryde Hall          Dept. of Computer Science
e-mail      : edwards@cs.vt.edu           U.S. mail: Virginia Tech (VPI&SU)
office phone: (540)-231-5723                         Blacksburg, VA  24061-0106
-------------------------------------------------------------------------------
```