From 33b5685770a9d4277cd1857a03cb1b205ffdccea Mon Sep 17 00:00:00 2001 From: Abhijeet Tiwari Date: Wed, 6 Oct 2021 11:02:07 +0530 Subject: [PATCH] change integer types to int64_t and uint64_t, as per the requirements. --- others/kadanes3.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/others/kadanes3.cpp b/others/kadanes3.cpp index cd56f3ecc..9032025de 100644 --- a/others/kadanes3.cpp +++ b/others/kadanes3.cpp @@ -26,8 +26,8 @@ * \returns maximum contiguous subarray sum */ template -int max_subarray_sum(std::array arr, int length) { - int current_max = INT_MIN, current_sum = 0; +int max_subarray_sum(std::array arr, uint64_t length) { + int64_t current_max = INT_MIN, current_sum = 0; for (int i = 0; i < length; i++) { current_sum = current_sum + arr[i]; if (current_max < current_sum) { @@ -46,14 +46,17 @@ int max_subarray_sum(std::array arr, int length) { * @returns void */ static void test() { - std::array arr = {1, 2, 3, 4}; - std::array arr1 = {-1, -2, -4, -6, 7}; + std::array arr = {1, 2, 3, 4}; + std::array arr1 = {-1, -2, -4, -6, 7}; assert(max_subarray_sum(arr, 4) == 10); assert(max_subarray_sum(arr1, 5) == 7); std::cout << "all test cases passed!"; } -/** main function */ +/** + * @brief Main function + * @returns 0 on exit + */ int main() { // Below is the code for accepting array from the user and then // calling the function for the required output. @@ -64,7 +67,7 @@ int main() { // std::size_t n; // variable for length of input array // std::cout << "Enter length of the array: "; // std::cin >> n; - // std::array arr = {0}; + // std::array arr = {0}; // // we need to give a constant in size. Hence we have allocated 100 // for now. // for (int i = 0; i < n; i++) @@ -72,18 +75,12 @@ int main() { // { // std::cin >> arr[i]; // } - // for (int i = 0; i < 100; i++) - // taking input of each element of the array - // - // { - // std::cout << arr[i] << std::endl; - // } + // code for accepting array from user ends // int max_sum = max_subarray_sum(arr, n); // std::cout << "Maximum contiguous sum for this array is : " << max_sum // << std::endl; - // code for accepting array from user ends test(); // run self-test implementations return 0; }