Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 MultiDimensonal Array Question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nathan4102




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: 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.
Raknarg




PostPosted: 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.
Nathan4102




PostPosted: 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!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: