formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -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);