- 论坛徽章:
- 0
|
RPG中是否真的無法解決二維陣列問題?
[quote]原帖由 "╰●-●╯"]這幾天遇到一個問題,需要用到二維陣列解決,但是RPG中的Array只能宣告一維,請問各位先進都是如何處理二維陣列的問題呢?[/quote 发表:
也许这段内容能给你一些启发,我不太清楚你要二维矩阵做什么用,不过这段
算法应该可以模拟二维矩阵,你自己研究一下吧。
my experience is
that you typically only want to reference one element at a time to
either save or retrieve the element's contents. With RPG IV, my
preference is to just code a little subprocedure to return the index
when passed the desired dimensions.
c eval Array( GetArrayIndex( X: Y )) = A
or
c eval A = Array( GetArrayIndex( X: Y ))
This technique allows you to code as many dimensions as you want, and
still be (relatively) readable. I don't put this one in a service
program, because I change the name of the procedure based on the
array, and change the number of arguments and array sizes.
By making the arguments Const, you can pass a variable, expression, or
constant for each dimension. For example, a simple program:
D Entry S 10A
D Array S Like( Entry )
D Dim( 6000 )
D GetArrayIndex PR 5I 0
D X 5I 0 Const
D Y 5I 0 Const
C Eval Array( GetArrayIndex( 1: 2 )) =
'Rhinoceros'
C Eval Entry = Array( GetArrayIndex( 1: 2
))
C Eval *InLR = *On
P GetArrayIndex B
D GetArrayIndex PI 5I 0
D X 5I 0 Const
D Y 5I 0 Const
D Array_Size_X C 100
D Array_Size_Y C 60
C Return (( X - 1 ) * Array_Size_X + Y )
P E |
|