Computer Science Canada

MultiDimensonal Array Question

Author:  Nathan4102 [ Fri Dec 12, 2014 9:58 pm ]
Post subject:  MultiDimensonal Array Question

Silly Question...

For a multidimensional array in Turing, e.g.

Turing:
var mapShapes : array 1 .. 23, 1 .. 4, 1 .. 2 of int


Is there syntax to access/assign the 1d/2d arrays within mapShapes? e.g. 2D - mapShapes[x], 1D - mapShapes[x][y].

I've tried the below code, but it doesn't compile unless I include all 3 parameters.

Thanks

Turing:
mapShapes(x, y) = (1, 2)

Author:  Zren [ Fri Dec 12, 2014 11:53 pm ]
Post subject:  RE:MultiDimensonal Array Question

In Turing, you can't really treat a multidimensional array like it's an array of an array unfortunately. At least not with that syntax.

Turing:

var a : array 1 .. 1, 1 .. 1 of int
var b : array 1 .. 1 of array 1 .. 1 of int

a (1, 1) := 1
b (1) (1) := 1

var c : array 1 .. 1 of int := init (1)
b (1) := c


You need to define the array like b is defined.

Author:  Raknarg [ Sat Dec 13, 2014 6:47 pm ]
Post subject:  RE:MultiDimensonal Array Question

Wow I never knew they were different, I assumed they were functionally identical.

Author:  Nathan4102 [ Sat Dec 13, 2014 9:22 pm ]
Post subject:  RE:MultiDimensonal Array Question

Huh I didn't even know arrays could be declared like b. It'll work for me, thanks!


: