
答案
正确答案为: if (deltaCol > deltaRow) {
fraction = (deltaRow * 2 – deltaCol)/2;
while (nextCol != endCol) {
if (fraction >= 0) {
nextRow = nextRow + stepRow;
fraction = fraction - deltaCol;
}
nextCol = nextCol + stepCol;
fraction = fraction + deltaRow;
pathRow[currentStep] = nextRow;
pathCol[currentStep] = nextCol;
currentStep++;
}
}
else {
fraction = (deltaCol * 2 – deltaRow)/2;
while (nextRow != endRow) {
if (fraction >= 0) {
nextCol = nextCol + stepCol;
fraction = fraction - deltaRow;
}
nextRow = nextRow + stepRow;
fraction = fraction + deltaCol;
pathRow[currentStep] = nextRow;
pathCol[currentStep] = nextCol;
currentStep++;
}
}