You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::collections::VecDeque;fnmain(){let ex = |q:&VecDeque<i32>,y:i32,desc:&str| {println!("search({}) -> {:?}\t# {}", y, q.binary_search_by(|&x| x.cmp(&y)), desc);};let q = VecDeque::from([1,2,3,5,6,7]);println!("q = {:?}", q);println!("q.len() = {:?}", q.len());ex(&q,0,"the left \"underflow\" yields an error at 0");ex(&q,1,"the first member yields an okay at the same index 0");ex(&q,4,"a missing member an error at the index it would be inserted in");ex(&q,5,"and the next member yields an okay at that same index");ex(&q,100,"the right \"overflow\" yields an error with the index equal to q.len()");}
q = [1, 2, 3, 5, 6, 7]
q.len() = 6
search(0) -> Err(0) # the left "underflow" yields an error at 0
search(1) -> Ok(0) # the first member yields an okay at the same index 0
search(4) -> Err(3) # a missing member an error at the index it would be inserted in
search(5) -> Ok(3) # and the next member yields an okay at that same index
search(100) -> Err(6) # the right "overflow" yields an error with the index equal to q.len()