#include using namespace std; class chess_block { public: bool bQueen; chess_block() { bQueen = false; } }; bool IsSafeToPutQueen(int nRow, int nCol, chess_block **Chess_Board, int n) { // We need to check for three directions upper left diagonal, lower left diagonal, and left horizontally; int nTempColLeft = nCol - 1; int nTempBelowRow = nRow + 1; int nTempAboveRow = nRow - 1; bool bSafe = true; // while (nTempColLeft >= 0 || nTempBelowRow= 0) { if (((nTempAboveRow >= 0) && (nTempColLeft >= 0) && (Chess_Board[nTempAboveRow][nTempColLeft].bQueen == true)) /*Left Upper Diagonal*/ || ((nTempBelowRow= 0) && (Chess_Board[nTempBelowRow][nTempColLeft].bQueen == true))/*Left Lower Diagonal*/ || ((nTempColLeft >= 0) && (Chess_Board[nRow][nTempColLeft].bQueen == true))) /*Left Block*/ { bSafe = false; break; } else { nTempColLeft--; nTempAboveRow--; nTempBelowRow++; } } return bSafe; } chess_block **PrepareTheChessBoard(int n)//Allocate memory for n*n blocks { //chess_block **Chess_Board= (chess_block **)malloc(n*sizeof(chess_block *)); chess_block **Chess_Board = new chess_block *[n]; for (int i = 0; i> n; chess_block **Chess_Board = NULL; Chess_Board = PrepareTheChessBoard(n); if (Chess_Board == NULL) { return 0; } ArrangeQueensOnBoard(Chess_Board, n); PrintPositionsOfQueens(Chess_Board, n); DestroyTheChessBoard(Chess_Board, n); Chess_Board = NULL; } return 0; }