TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Efficient implementation for maximum contiguous subarray sum by Kadane's algorithm. More...
#include <array>
#include <cassert>
#include <climits>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
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.
Definition in file kadanes3.cpp.
int main | ( | void | ) |
Main function.
Definition at line 60 of file kadanes3.cpp.
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 |
Definition at line 29 of file kadanes3.cpp.
|
static |
Self-test implementations.
Definition at line 48 of file kadanes3.cpp.