Content deleted Content added
→Empty subarrays admitted: introduce line numbers everywhere in code |
→No empty subarrays admitted: if nonempty just use first element |
||
Line 90:
current_sum = max(x, current_sum + x)
</syntaxhighlight>
In that case, if the input contains no positive element, the returned value is that of the largest element (i.e., the value closest to 0), or negative infinity if the input was empty. For correctness, an exception should be raised when the input array is empty, since an empty array has no maximum nonempty subarray. If the array is non-empty, its first element can be used in place of negative infinity, if needed to avoid mixing numeric and non-numeric values.
===Computing the best subarray's position===
|