[feat/fix/docs]: Improvements in the backtracking folder (#1553)

* [feat/fix/docs]: Improvements in the...

...`backtracking` folder, and minor fixes in the `others/iterative_tree_traversals.cpp` and the `math/check_prime.cpp` files.

* clang-format and clang-tidy fixes for 9cc3951d

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Abhinn Mishra <49574460+mishraabhinn@users.noreply.github.com>
This commit is contained in:
David Leal
2021-10-29 13:05:46 -05:00
committed by GitHub
parent a9312b3901
commit 4e3abd4601
8 changed files with 367 additions and 322 deletions

View File

@@ -1,14 +1,14 @@
/**
* @file
* @brief [Eight Queens](https://en.wikipedia.org/wiki/Eight_queens_puzzle)
* @brief [Eight Queens](https://en.wikipedia.org/wiki/Eight_queens_puzzle)
* puzzle, printing all solutions
*
* @author [Himani Negi](https://github.com/Himani2000)
* @author [David Leal](https://github.com/Panquesito7)
*
*/
#include <iostream>
#include <array>
#include <array> /// for std::array
#include <iostream> /// for IO operations
/**
* @namespace backtracking
@@ -17,12 +17,13 @@
namespace backtracking {
/**
* @namespace n_queens_all_solutions
* @brief Functions for [Eight
* Queens](https://en.wikipedia.org/wiki/Eight_queens_puzzle) puzzle with all solutions.
* @brief Functions for the [Eight
* Queens](https://en.wikipedia.org/wiki/Eight_queens_puzzle) puzzle with all
* solutions.
*/
namespace n_queens_all_solutions {
/**
* Utility function to print matrix
* @brief Utility function to print matrix
* @tparam n number of matrix size
* @param board matrix where numbers are saved
*/
@@ -38,7 +39,7 @@ void PrintSol(const std::array<std::array<int, n>, n>& board) {
}
/**
* Check if a queen can be placed on matrix
* @brief Check if a queen can be placed on the matrix
* @tparam n number of matrix size
* @param board matrix where numbers are saved
* @param row current index in rows
@@ -47,7 +48,8 @@ void PrintSol(const std::array<std::array<int, n>, n>& board) {
* @returns `false` if queen can't be placed on matrix
*/
template <size_t n>
bool CanIMove(const std::array<std::array<int, n>, n>& board, int row, int col) {
bool CanIMove(const std::array<std::array<int, n>, n>& board, int row,
int col) {
/// check in the row
for (int i = 0; i < col; i++) {
if (board[row][i] == 1) {
@@ -70,7 +72,7 @@ bool CanIMove(const std::array<std::array<int, n>, n>& board, int row, int col)
}
/**
* Solve n queens problem
* @brief Main function to solve the N Queens problem
* @tparam n number of matrix size
* @param board matrix where numbers are saved
* @param col current index in columns
@@ -89,11 +91,12 @@ void NQueenSol(std::array<std::array<int, n>, n> board, int col) {
}
}
}
} // namespace n_queens_all_solutions
} // namespace n_queens_all_solutions
} // namespace backtracking
/**
* Main function
* @brief Main function
* @returns 0 on exit
*/
int main() {
const int n = 4;