Introduction to OOP | Chapter 6: The Eight Queens Puzzle: | next | previous | audio | real | text |
Initialization will set each queen to point to a neighbor, and set column value. C++ version is shown:
main() { Queen * lastQueen = 0; for (int i = 1; i <= 8; i++) { lastQueen = new Queen(i, lastQueen); if (! lastQueen->findSolution()) cout << "no solution"; } if (lastQueen->first()) lastQueen->print(); } Queen::Queen (int col, Queen * ngh) { column = col; neighbor = ngh; row = 1; }