Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Efficient implementation for maximum contiguous subarray sum by Kadane's algorithm. More...
#include <array>
#include <cassert>
#include <climits>
#include <iostream>
Functions | |
template<std::size_t SIZE> | |
int | max_subarray_sum (std::array< int64_t, SIZE > arr, uint64_t length) |
for IO operations | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Efficient implementation for maximum contiguous subarray sum by Kadane's algorithm.
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.
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.
int main | ( | void | ) |
Main function.
int max_subarray_sum | ( | std::array< int64_t, SIZE > | arr, |
uint64_t | length ) |
for IO operations
for std::array for assert for INT_MIN value
Utility function to check the current maximum number
arr | input array |
length | length of the input array |
|
static |
Self-test implementations.