An open API service indexing awesome lists of open source software.

https://github.com/mokira3d48/rust-binary-search

An implementation of the binary search algorithm in Rust.
https://github.com/mokira3d48/rust-binary-search

binary-search rust-lang searching-algorithms

Last synced: 2 months ago
JSON representation

An implementation of the binary search algorithm in Rust.

Awesome Lists containing this project

README

        

# Rust Binary Search
An implementation of the binary search algorithm in Rust.

## Usage

```rust
mod binary_search;

fn main() {
let array_sorted: Vec = vec![2, 3, 4, 5, 6];
// We want to find number 5 and 10 in this array:
let result1 = binary_search::find(array_sorted.as_slice(), 5);
let result2 = binary_search::find(array_sorted.as_slice(), 10);

match result1 {
Some(pos) => println!("The position of {} is: {}", 5, pos),
None => println!("The number {} is not found.", 5),
};
match result2 {
Some(pos) => println!("The position of {} is: {}", 10, pos),
None => println!("The number {} is not found.", 10),
};
}
```

Output:

```
The position of 5 is: 3
The number 10 is not found.
```