queen类定义如下:class Queen{
public:
Queen(int, Queen*);
bool findSolution();
bool advance();
void print();
private:
int row;
const int column;
Queen* neighbor;
bool canAttack(int, int);
};
Queen::Queen(int col, Queen* ngh):
column(col),neighbor(ngh){
row=1;
}
bool Queen::canAttack(int testRow, int testColumn) {
if(row == testRow)
return true;
int columnDifference = testColumn-column;
if((row + columnDifference == testRow) ||
(row - columnDifference == testRow))
return true;
return neighbor && neighbor->canAttack(testRow, testColumn);
}
bool Queen::findSolution() {
while(neighbor && neighbor->canAttack(row,column))
if(!advance())
return false;
return true; }
bool Queen::advance() {
if(row<8){
row++;
return findSolution();
}
if(neighbor&&!neighbor->advance())
return false;
row=1;
return findSolution();
}
问:如何定义print函数输出所有结果(可在上述基础上对已定义函数进行适当修改),求高人指导。急!!!!
自己上网搜索借鉴一下他人的吧,懒的看代码逻辑