mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-11-27 22:24:29 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -2,18 +2,15 @@
|
||||
#define N 4
|
||||
using namespace std;
|
||||
|
||||
void printSolution(int board[N][N])
|
||||
{
|
||||
void printSolution(int board[N][N]) {
|
||||
cout << "\n";
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) cout << "" << board[i][j];
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
bool isSafe(int board[N][N], int row, int col)
|
||||
{
|
||||
bool isSafe(int board[N][N], int row, int col) {
|
||||
int i, j;
|
||||
|
||||
/* Check this row on left side */
|
||||
@@ -34,22 +31,18 @@ bool isSafe(int board[N][N], int row, int col)
|
||||
return true;
|
||||
}
|
||||
|
||||
void solveNQ(int board[N][N], int col)
|
||||
{
|
||||
if (col >= N)
|
||||
{
|
||||
void solveNQ(int board[N][N], int col) {
|
||||
if (col >= N) {
|
||||
printSolution(board);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Consider this column and try placing
|
||||
this queen in all rows one by one */
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int i = 0; i < N; i++) {
|
||||
/* Check if queen can be placed on
|
||||
board[i][col] */
|
||||
if (isSafe(board, i, col))
|
||||
{
|
||||
if (isSafe(board, i, col)) {
|
||||
/* Place this queen in board[i][col] */
|
||||
// cout<<"\n"<<col<<"can place"<<i;
|
||||
board[i][col] = 1;
|
||||
@@ -62,8 +55,7 @@ void solveNQ(int board[N][N], int col)
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int board[N][N] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
|
||||
|
||||
solveNQ(board, 0);
|
||||
|
||||
Reference in New Issue
Block a user