From 51e1dda02e6f0e0440647d9ab2ff9e51c7907402 Mon Sep 17 00:00:00 2001 From: Alvin Philips Date: Sun, 24 Oct 2021 06:18:26 +0530 Subject: [PATCH] fix: Union of two arrays (#1794) * Create reverse_binary_tree.cpp * Added documentation Added Documentation for the level_order_traversal() function, and implemented a print() function to display the tree to STDOUT * Added documentation * Renamed tests to test * Fixed issue with incorrect using statement * updating DIRECTORY.md * clang-format and clang-tidy fixes for fb86292d * Added Test cases * Update operations_on_datastructures/reverse_binary_tree.cpp Co-authored-by: David Leal * Update operations_on_datastructures/reverse_binary_tree.cpp Co-authored-by: David Leal * Update operations_on_datastructures/reverse_binary_tree.cpp Co-authored-by: David Leal * Update operations_on_datastructures/reverse_binary_tree.cpp Co-authored-by: David Leal * Update operations_on_datastructures/reverse_binary_tree.cpp Co-authored-by: David Leal * Changed int to int64_t * Updated documentation wording * Fixed wrong integer type Changed int64_t to int32_t * clang-format and clang-tidy fixes for 2af706b1 Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: David Leal --- math/check_prime.cpp | 18 +++++++++--------- .../union_of_two_arrays.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/math/check_prime.cpp b/math/check_prime.cpp index 1e1bd975a..a7b313551 100644 --- a/math/check_prime.cpp +++ b/math/check_prime.cpp @@ -7,12 +7,13 @@ * @brief * Reduced all possibilities of a number which cannot be prime. * Eg: No even number, except 2 can be a prime number, hence we will increment - * our loop with i+6 jumping and check for i or i+2 to be a factor of the number; - * if it's a factor then we will return false otherwise true after the loop terminates at the terminating condition which is (i*i<=num) + * our loop with i+6 jumping and check for i or i+2 to be a factor of the + * number; if it's a factor then we will return false otherwise true after the + * loop terminates at the terminating condition which is (i*i<=num) */ -#include /// for assert -#include /// for IO operations +#include /// for assert +#include /// for IO operations /** * Function to check if the given number is prime or not. @@ -24,14 +25,13 @@ bool is_prime(T num) { bool result = true; if (num <= 1) { return false; - } else if (num == 2 || num==3) { + } else if (num == 2 || num == 3) { return true; - } else if ((num%2) == 0 || num%3 == 0) { + } else if ((num % 2) == 0 || num % 3 == 0) { return false; - } - else { + } else { for (T i = 5; (i * i) <= (num); i = (i + 6)) { - if ((num % i) == 0 || (num%(i+2)==0 )) { + if ((num % i) == 0 || (num % (i + 2) == 0)) { result = false; break; } diff --git a/operations_on_datastructures/union_of_two_arrays.cpp b/operations_on_datastructures/union_of_two_arrays.cpp index 45433379e..d2a621440 100644 --- a/operations_on_datastructures/union_of_two_arrays.cpp +++ b/operations_on_datastructures/union_of_two_arrays.cpp @@ -28,7 +28,7 @@ namespace operations_on_datastructures { * @returns void */ void print(const std::vector &array) { - for (int64_t i : array) { + for (int32_t i : array) { std::cout << i << " "; /// Print each value in the array } std::cout << "\n"; /// Print newline