3个稳定版本
1.0.2 | 2024年3月5日 |
---|---|
1.0.1 | 2024年3月4日 |
#1106 in 算法
69 每月下载量
24KB
371 行
算法沙盒
算法沙盒是一个Rust库,提供了各种搜索算法的实现。
特性
- 包括搜索和排序算法的实现。
- 适用于实现了
PartialEq
或Ord
特质的任何类型。
安装
要在您的Rust项目中使用算法沙盒,请在您的Cargo.toml
文件中将它添加为依赖项
[dependencies]
algorithm_playground = "1.0.2"
用法
以下是如何在Rust代码中使用搜索算法的示例
use algorithm_playground::algorithms::searching::searching::{linear_search, binary_search};
fn main() {
let arr = vec![1, 2, 3, 4, 5];
// Perform linear search
match linear_search(&arr, &3) {
Some(index) => println!("Found 3 at index {}", index),
None => println!("3 not found"),
}
// Perform binary search (requires sorted array)
match binary_search(&arr, &3) {
Some(index) => println!("Found 3 at index {}", index),
None => println!("3 not found"),
}
}
贡献
欢迎为算法沙盒做出贡献!如果您发现了一个错误或有一个功能请求,请在GitHub上创建一个问题。我们也欢迎Pull requests。
许可证
本项目采用MIT许可证 - 请参阅LICENSE文件以获取详细信息。