【发布时间】:2013-04-06 16:11:05
【问题描述】:
基本上,我的第一个任务是将“0”的位置保存为整数。使用标准数组非常简单。此代码循环遍历数组(大小:8),直到找到 0,然后将其保存为位置。见以下代码:
p.s: n 是对保存在其他地方的数组的引用。
int position = 0;
this.nodesExpanded++;
// Loop through the array to get the position of where '0' is
for (int i = 0; i < n.getPuzzle().length; i++){
if (n.getPuzzle()[i] == 0){
position = i;
break;
}
}
我的最终任务是使多维数组(大小:[3, 3])成为可能。所以这是我迄今为止创建的:
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
{
if (n.getPuzzle()[x,y] == 0)
{
**position = ;**
break;
}
}//end y loop
}//end x loop
那么我该如何将一个数组引用保存到一个值中呢? 我猜“位置”需要是 int 以外的东西..
如果您需要更多说明,请务必发表评论,提前抱歉并感谢您!
【问题讨论】: