From 508590b6b15d9d0e2231d998f5f5fd425f34c262 Mon Sep 17 00:00:00 2001 From: Abhijeet Tiwari Date: Wed, 6 Oct 2021 07:58:37 +0530 Subject: [PATCH] DIRECTORY.md and kadanes3.cpp modified --- DIRECTORY.md | 1 + others/kadanes3.cpp | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 528fb0add..7193e8b1f 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -248,6 +248,7 @@ * [Fast Integer Input](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/fast_integer_input.cpp) * [Happy Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/happy_number.cpp) * [Iterative Tree Traversals](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/iterative_tree_traversals.cpp) + * [Kadanes3](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/kadanes3.cpp) * [Lru Cache](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/lru_cache.cpp) * [Matrix Exponentiation](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/matrix_exponentiation.cpp) * [Palindrome Of Number](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/others/palindrome_of_number.cpp) diff --git a/others/kadanes3.cpp b/others/kadanes3.cpp index 3ac9fec72..cd56f3ecc 100644 --- a/others/kadanes3.cpp +++ b/others/kadanes3.cpp @@ -1,27 +1,26 @@ /** * @file - * @brief Efficient implemention for maximum contiguos subarray sum by kadane's - * algorithm. + * @brief Efficient implementation for maximum contiguous subarray sum by + * [Kadane's + * algorithm](https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/). * @details * Our task is to take length of array and then the whole array as input from * the user and then calculate the maximum contiguos subarray sum for the * input array, using the kadane's algorithm. * - * reference article : - * https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/ - * * There can be a case that all the elements in the input array are negative. * In that case, the least value among all elements is the maximum sum with * subarray length = 1. * @author [Abhijeet Tiwari](https://github.com/thisabhijeet) */ -#include -#include // for assert -#include // for INT_MIN value -#include // for io operations +#include /// for std::array +#include /// for assert +#include /// for INT_MIN value +#include /// for IO operations -/** max_subarray_sum function +/** + * @brief Utility function to check the current maximum number * \param arr input array * \param length length of the input array * \returns maximum contiguous subarray sum @@ -46,7 +45,6 @@ int max_subarray_sum(std::array arr, int length) { * @brief Self-test implementations * @returns void */ - static void test() { std::array arr = {1, 2, 3, 4}; std::array arr1 = {-1, -2, -4, -6, 7}; @@ -57,10 +55,10 @@ static void test() { /** main function */ int main() { - // Below is the code for accepting array from user and then + // Below is the code for accepting array from the user and then // calling the function for the required output. // It has been commented for now so that the test() function can run - // and test cases can be verified. + // and the test cases can be verified. // code for accepting array from user starts // std::size_t n; // variable for length of input array @@ -86,6 +84,6 @@ int main() { // << std::endl; // code for accepting array from user ends - test(); + test(); // run self-test implementations return 0; -} \ No newline at end of file +}