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.
- Host: GitHub
- URL: https://github.com/mokira3d48/rust-binary-search
- Owner: mokira3d48
- Created: 2024-09-10T06:39:50.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-09-10T07:55:55.000Z (9 months ago)
- Last Synced: 2025-01-20T06:16:20.340Z (4 months ago)
- Topics: binary-search, rust-lang, searching-algorithms
- Language: Rust
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.
```