DIRECTORY.md and kadanes3.cpp modified

This commit is contained in:
Abhijeet Tiwari
2021-10-06 07:58:37 +05:30
parent b7f81a5d2e
commit 508590b6b1
2 changed files with 14 additions and 15 deletions

View File

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

View File

@@ -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 <array>
#include <cassert> // for assert
#include <climits> // for INT_MIN value
#include <iostream> // for io operations
#include <array> /// for std::array
#include <cassert> /// for assert
#include <climits> /// for INT_MIN value
#include <iostream> /// 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<int, SIZE> arr, int length) {
* @brief Self-test implementations
* @returns void
*/
static void test() {
std::array<int, 4> arr = {1, 2, 3, 4};
std::array<int, 5> 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;
}
}