160 likes | 234 Views
int matrixArray[12]. The elements in an array are stored in a series of contiguous memory locations, each holding a piece of integer data. Often we represent data in different structures, such as a Matrix. Why? Picture files (gifs, bitmaps or jpegs) Area Plots. Note!
E N D
intmatrixArray[12] The elements in an array are stored in a series of contiguous memory locations, each holding a piece of integer data. Often we representdata in different structures, such as a Matrix. • Why? • Picture files (gifs, bitmaps or jpegs) • Area Plots Note! It is still a linear array of integers in our code. But we want to treat it as a Matrix.
intmatrixArray[12] Row = 3 Coln = 4
intmatrixArray[12] Row = 3 Coln = 4
intmatrixArray[12] Row = 3 Coln = 4
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln)
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln)
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln) (0 * 4) = 0
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln) (0 * 4) = 0 (1 * 4) = 4
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln) (0 * 4) = 0 (1 * 4) = 4 (2 * 4) = 8
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln) + c (0 * 4) = 0 (1 * 4) = 4 (2 * 4) = 8
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln) + c (0 * 4) = 0 + 1 = 1 (1 * 4) = 4 + 1 = 5 (2 * 4) = 8 + 1 = 9
intmatrixArray[12] intgetIndex(intr, intc, intcoln, introw) Row = 3 Coln = 4 Index = (r * coln) + c (0 * 4) = 0 + 2 = 2 (1 * 4) = 4 + 2 = 6 (2 * 4) = 8 + 2 = 10
intmatrixArray[12] void getRowColn(intindex,intcoln, introw, int&r, int&c) Row = 3 Coln = 4
intmatrixArray[12] void getRowColn(intindex,intcoln, introw, int&r, int&c) Row = 3 Coln = 4 r = i / coln; c = i % coln; r = 6 / 4 = 1 c = 6 % 4 = 2
intmatrixArray[12] Row = 3 Coln = 4