pub fn linear_search<T>(arr: &[T], target: &T) -> Option<usize>where
T: PartialEq,Expand description
线性搜索/Linear search
§参数/Arguments
arr- 要搜索的数组/The array to searchtarget- 要查找的目标/The target to find
§返回值/Returns
目标索引(如果找到)/Index of target if found
§示例/Examples
use slice_reducer::linear_search;
let arr = [10, 20, 30];
assert_eq!(linear_search(&arr, &20), Some(1));
assert_eq!(linear_search(&arr, &40), None);