求八皇后问题C++程序设计
来源:百度知道 编辑:UC知道 时间:2024/05/21 07:11:47
#ifndef _QUEENBOARD_H_
#define _QUEENBOARD_H_
const int BOARDSIZE = 8;
using namespace std;
class Queenboard {
private:
bool board[BOARDSIZE][BOARDSIZE];
public:
Queenboard();
bool is_space_under_attack(int, int) const;
void occupy_space(int, int);
void clear_column(int);
friend ostream& operator<<(ostream& out, const Queenboard& cb);
};
Queenboard::Queenboard() {
// Initialize the board to contain zero queens.
for (int row = 0; row < BOARDSIZE; row++) {
for (int col = 0; col < BOARDSIZE; col++) {
board[row][col] = false;
}
}
}
ostream& operator<<(ostream& out, const Queenboard& cb) {
// output the board
for (int row = 0; row < BOARDSIZE; row++) {
out << "---------------------------------" << endl;
for (int col =