Я пытаюсь выполнить итерацию по списку «breadthBoard» и добавить к нему массив «доска». Однако каждый массив, который я добавляю в массив, каким-то образом превращается в исходный массив, который затем дублируется, хотя я тестировал массив, который был изменен.Невозможно добавить в ArrayList
neighbourNodes - это список, который содержит все значения, смежные с currentNode на плате.
public List breadthBoard(List neighbourNodes, int [] currentNode, int [][] board)
{
int x = currentNode[0] - 1;
int y = currentNode[1] - 1;
//create lists
List breadthBoard = new ArrayList();
for (int i=0; i<3;i++)
{
for(int j=0; j<3;j++)
{
if (neighbourNodes.contains(board[i][j]))
{
// the temp variables allow me to switch the values then switch back later on
int temp = board[i][j];
int temp2 = board[x][y];
//initial switch
board[i][j] = temp2;
board[x][y] = temp;// at this point I get a successful swap but it isn't getting added to the breadth board
breadthBoard.add(board);
//test to see if I get the right results which I do
System.out.println("what's being added into breadth board (should be swapped)" + Arrays.deepToString(board));
System.out.println('\n');
switching the values back to the original postions
board[i][j] = temp;
board[x][y] = temp2;
System.out.print("back to normal " + Arrays.deepToString(board));// another test passed
System.out.println('\n');
}
}
Где вы получаете 'x' и' y' от и что neighbourNodes ? –
Нам нужно знать больше о том, что происходит. Где объявляется ширина, утверждается, что это за тип? –
Я добавлю остальную часть метода –