Struct max_subarray_sum::Elements[][src]

pub struct Elements<'list> { /* fields omitted */ }
Expand description

The Elements struct holds the list and related pieces of informations of it.

Implementations

Returns a new instance of Elements.

Examples

use max_subarray_sum::Elements;

let mut list: Vec<i32> = vec![-2, -3, 4, -1, -2, 1, 5, -3];

let len: usize = list.len();

let mut elements = Elements::new(&mut list, len);

This method finds the max subarray sum. If there are multiple subarrays with equal sum it selects the subarray that came first.

This method returns the max subarray sum. We need to chain this method with find_max_sum.

Examples

use max_subarray_sum::Elements;

let mut list: Vec<i32> = vec![-2, -3, 4, -1, -2, 1, 5, -3];

let len: usize = list.len();

let mut elements = Elements::new(&mut list, len);

let max_sum: i32 = elements.find_max_sum().result();

assert_eq!(7, max_sum);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.