2D arrays
Author |
Message |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Mon Mar 07, 2005 6:47 pm Post subject: 2D arrays |
|
|
I know what 2D arrays are but i have a question on hwo to use them, for example if i have a 2D array, how do i get them to match each other for example :
1st -> 1st
1st -> 2nd
1st -> 3rd
2nd -> 1st
2nd -> 2nd
2nd -> 3rd
3rd -> 1st
3rd -> 2nd
3rd -> 3rd
Match each other, hard to understand?? =S |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
person
|
Posted: Mon Mar 07, 2005 6:49 pm Post subject: (No subject) |
|
|
wat does -> mean? |
|
|
|
|
![](images/spacer.gif) |
Flikerator
|
Posted: Mon Mar 07, 2005 8:18 pm Post subject: (No subject) |
|
|
person wrote: wat does -> mean?
I think it means "=". |
|
|
|
|
![](images/spacer.gif) |
ssr
![](http://siruisite.port5.com/ssr.jpg)
|
Posted: Mon Mar 07, 2005 8:59 pm Post subject: (No subject) |
|
|
do u get the question though?
umm
do u wanna replace all the values in the array that has the index with the same values?
ummm ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
Flikerator
|
Posted: Mon Mar 07, 2005 9:28 pm Post subject: (No subject) |
|
|
code: |
var nums : array 1 .. 3 of int
for i : 1 .. 3
nums (i) := 1
end for
|
Now they all equal 1. Is that what you wanted? Not sure what is meant by 2D array (Never heard of them). |
|
|
|
|
![](images/spacer.gif) |
person
|
Posted: Mon Mar 07, 2005 9:30 pm Post subject: (No subject) |
|
|
2D arrays r arrays wich r stored in an array...i know someone (probably Cervantes) wrote a tutorial on it...all i remember was wat 2D arrays r and that it was a good tutorial |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Mon Mar 07, 2005 9:51 pm Post subject: (No subject) |
|
|
ex)
code: | var test:array 1..5,1..5 of int
for i:1..5
for a:1..5
test(i,a):=i*a
end for
end for | that right there is a 2d array. so each array of 1..5 has another array of 1..5, so test(1,1) would = 1 , test(3,5) would = 15. hm.. maybe like a graph may work to explain best
code: | test(1,*)= test(1,1)
test(1,2)
test(1,3)
test(1,4)
test(1,5)
test(2,*)= test(2,1)
test(2,2)
test(2,3)
test(2,4)
test(3,5)
test(3,*)= test(3,1)
test(3,2)
test(3,3)
test(3,4)
test(3,5)
test(4,*)= test(4,1)
test(4,2)
test(4,3)
test(4,4)
test(4,5)
test(5,*)= test(5,1)
test(5,2)
test(5,3)
test(5,4)
test(5,5) | kinda like that lol |
|
|
|
|
![](images/spacer.gif) |
person
|
Posted: Tue Mar 08, 2005 3:32 pm Post subject: (No subject) |
|
|
thats 2D arryas in a nutshell!!!
btw: ur not limited to just 2 dimensions, u can go all the way to watever if u like but that would be confusing and....(i digress)...... |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Token
![](http://server2.uploadit.org/files/token89-avatar1.jpg)
|
Posted: Tue Mar 08, 2005 3:50 pm Post subject: (No subject) |
|
|
okay now i have a question, is it possible to have a string variable inside an integer variable, or vice versa? like for example a high score, i would want to store the persons username and then theyre score, i could put them both into a string array but then i wouldent be able to sort them unless i used the strint function, any ideas? |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Tue Mar 08, 2005 4:58 pm Post subject: (No subject) |
|
|
i sugest using records
code: |
var player:array 1..2 of
record
name:string
score:int
end record |
|
|
|
|
|
![](images/spacer.gif) |
Flikerator
|
Posted: Wed Mar 09, 2005 4:06 pm Post subject: (No subject) |
|
|
Its easy to suggest records when you don't explain how to use them
Yah after I asked what 2D arrays where I read a tutorial on them...Thanks though
Records are VERY useful with arrays/flexible arrays. |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Wed Mar 09, 2005 4:38 pm Post subject: (No subject) |
|
|
srry i think kinda wierd and in my own way so i dont think to explain things at first
code: | var player:array 1..2 of %making an array of 1..2 of the following
record %starts the record lol
name:string %gives the variable player(x) a sub variable
score:int %adds another subvariable
end record %end the record, could have more variable if wanted |
as an example you would do:
player(1).name:="Bob"
player(1).score:=13
that way 'Bob' would have a score of '13' sotred under the same variable, you can make a type by using records (pretty sure in tutorial) and u can even use records in records if you wanted to. just an easy way to store sub variable uynder one name to keep track of them |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Fri Mar 11, 2005 7:18 pm Post subject: (No subject) |
|
|
Bacchus wrote: ex)
code: | var test:array 1..5,1..5 of int
for i:1..5
for a:1..5
test(i,a):=i*a
end for
end for | that right there is a 2d array. so each array of 1..5 has another array of 1..5, so test(1,1) would = 1 , test(3,5) would = 15. hm.. maybe like a graph may work to explain best
code: | test(1,*)= test(1,1)
test(1,2)
test(1,3)
test(1,4)
test(1,5)
test(2,*)= test(2,1)
test(2,2)
test(2,3)
test(2,4)
test(3,5)
test(3,*)= test(3,1)
test(3,2)
test(3,3)
test(3,4)
test(3,5)
test(4,*)= test(4,1)
test(4,2)
test(4,3)
test(4,4)
test(4,5)
test(5,*)= test(5,1)
test(5,2)
test(5,3)
test(5,4)
test(5,5) | kinda like that lol
Yea its something like that but if the first array is 2, 4, 5, 6, 3 and the second array is 3, 2, 5, 6, 1
then
if
2 matches 3 then do blah
2 matches 2 then do blah
2 matches 5 then do blah
2 matches 6 then do blah
2 matches 1 then do blah
4 matches 3 then do blah
4 matches 2 then do blah
4 matches 5 then do blah
4 matches 6 then do blah
4 matches 1 then do blah
5 matches 3 then do blah
5 matches 2 then do blah
5 matches 5 then do blah
5 matches 6 then do blah
5 matches 1 then do blah
=S |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Fri Mar 11, 2005 7:28 pm Post subject: (No subject) |
|
|
try nested for loops
code: | for i:1..upper(array1)
for a:1..upper(array2)
if array1(i)=array2(a) then
%do stuff
end if
end for
end for |
|
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Fri Mar 18, 2005 5:39 pm Post subject: (No subject) |
|
|
cool thanks ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|