0
填充算法我已经广泛地搜查了论坛,并没有颇为涵盖这一点。我正在寻找在枚举类型的数组上实质上称为3D Flood Fill算法的算法。我不想改变数组元素的“颜色”,而是想改变枚举类型。这是我迄今为止,如果你认为这会起作用或者你有什么建议,你们可以让我知道吗?3D洪水在3D阵列(爪哇)
/*
* CellType is my enum type. BOUNDRY_BOX enum type is type that I line the whole 3D array with. So the
* whole inside surface of the 3D box is filled with CellType.BOUNDRY_BOX.
**/
public void fillAllVoidCells(CellType[][][] grid, CellType targetType, CellType replacementType, int x, int y, int z)
{
if ((grid[x][y][z] != targetType) && grid[x][y][z] != CellType.BOUNDRY_BOX)
{
break;
}
else
{
grid[x][y][z] = replacementType;
fillAllVoidCells(grid, targetType, replacementType, x + 1, y, z); // right
fillAllVoidCells(grid, targetType, replacementType, x - 1, y, z); // left
fillAllVoidCells(grid, targetType, replacementType, x, y + 1, z); // in front
fillAllVoidCells(grid, targetType, replacementType, x, y - 1, z); // behind
fillAllVoidCells(grid, targetType, replacementType, x, y, z + 1); // above
fillAllVoidCells(grid, targetType, replacementType, x, y, z - 1); // below
}
}
感谢你的帮助,这是非常有用的。我已经取得了很大的进展,请您在这里提出后续问题? http://stackoverflow.com/questions/16294856/using-recursion-for-3d-array-manipulation-causing-stackoverflow-not-infinite – 2013-04-30 07:54:16