Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Binary-search/Rust/binary-search.rust
Normal file
17
Task/Binary-search/Rust/binary-search.rust
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
fn binary_search<T:PartialOrd>(v: &[T], searchvalue: T) -> Option<T> {
|
||||
let mut lower = 0 as usize;
|
||||
let mut upper = v.len() - 1;
|
||||
|
||||
while upper >= lower {
|
||||
let mid = (upper + lower) / 2;
|
||||
if v[mid] == searchvalue {
|
||||
return Some(searchvalue);
|
||||
} else if searchvalue < v[mid] {
|
||||
upper = mid - 1;
|
||||
} else {
|
||||
lower = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue