Function algos::search::linear[][src]

pub fn linear<T: Ord>(a: &[T], x: &T) -> Result<usize, usize>

Linear Search: Search for the value 'x' in an array.

Returns Err holding the last iterator if 'x' not found and array[i] > x.

Case Time complexity Space complexity
Best: Ω(1)
Avrg: θ(n)
Worst: O(n) O(1)

Example

use algos::search;

let v = [1, 3, 4, 8, 11, 17, 23];

let find = search::linear(&v, &11);
assert_eq!(find, Ok(4));

let find2 = search::linear(&v, &19);
assert_eq!(find2, Err(6));