A small crate of commonly used sorting algorithms for any generic type that implements PartialOrd and copy.
The crate can be found here: Crate
rust
[dependencies]
rs_algo = "0.1"
```rust extern crate rs_algo;
use rsalgo::sort::*; use rsalgo::compare::{LCSubsequence, LCSubstring};
fn main() { let mut a = vec![117, 1, 3, 99, 10, 7, 17, 2, 11, -6, 4, 9, 10, 7, 2, 11, -5, 4, 9, 7, 2, 11, -5, 4, 9, 8]; let mut b = vec![117, 1, 3, 99, 10, 7, 17, 2, 11, -6, 4, 9, 10, 7, 2, 11, -5, 4, 9, 7, 2, 11, -5, 4, 9, 8]; let mut c = vec![117, 1, 3, 99, 10, 7, 17, 2, 11, -6, 4, 9, 10, 7, 2, 11, -5, 4, 9, 7, 2, 11, -5, 4, 9, 8]; let mut d = vec![117, 1, 3, 99, 10, 7, 17, 2, 11, -6, 4, 9, 10, 7, 2, 11, -5, 4, 9, 7, 2, 11, -5, 4, 9, 8];
// This will sort the vector passed in, changing the original vector order merge::sort(&mut a); quick::sort(&mut b); insertion::sort(&mut c); bubble::sort(&mut d);
// Or if want the time taken you can use sortwithtime // // let time = merge::sortwithtime(&mut a); // let time = quick::sortwithtime(&mut b); // let time = insertion::sortwithtime(&mut c); // let time = bubble::sortwithtime(&mut d);
// get a new longest common sequence object let sequence = LCSubsequence::newsubsequence("leighxxxft".tostring(), "right".tostring()); asserteq!(sequence.subsequencelen, 4); asserteq!(sequence.getlongestsubsequence(), Some("ight".to_string()));
// get a new longest common substring let substring = LCSubstring::newsubstring("!!!!Hello WorldXXXXX".tostring(), "XX Hello World@cvcvcvc".tostring()); asserteq!(substring.substringlen, 11); asserteq!(substring.getlongestsubstring(), Some("Hello World".to_string())); } ```
MIT