Crates.io | sort_algorithms |
lib.rs | sort_algorithms |
version | 0.3.5 |
source | src |
created_at | 2021-12-06 18:42:39.2091 |
updated_at | 2024-07-26 19:15:59.018563 |
description | This package has the implementation of several sort algorithms |
homepage | https://github.com/GabrielBernardoDaSilva/sort |
repository | https://github.com/GabrielBernardoDaSilva/sort |
max_upload_size | |
id | 493327 |
size | 26,859 |
extern crate sort_algorithms;
use sort_algorithms::selection_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
selection_sort(&mut arr, |a, b| a < b);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
extern crate sort_algorithms;
use sort_algorithms::bubble_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
bubble_sort(&mut arr, |a, b| a < b);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
extern crate sort_algorithms;
use sort_algorithms::quick_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
quick_sort(&mut arr, |a, b| a < b);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
extern crate sort_algorithms;
use sort_algorithms::heapsort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
heapsort(&mut arr);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
extern crate sort_algorithms;
use sort_algorithms::merge_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
merge_sort(&mut arr, |a, b| a < b);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
Can only be used to sort lists of positive integers as key
extern crate sort_algorithms;
use sort_algorithms::radix_sort;
fn main() {
let mut arr = vec![7, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
radix_sort(&mut arr, |&a| a);
println!("{:?}", &arr);
assert_eq!(arr, [ 0, 1, 2, 3, 4, 5, 6, 7]);
}
extern crate sort_algorithms;
use sort_algorithms::insertion_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
insertion_sort(&mut arr, |a, b| a < b);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
extern crate sort_algorithms;
use sort_algorithms::cocktail_shaker_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
cocktail_shaker_sort(&mut arr, |a, b| a < b);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}
Can only be used to sort lists of positive integers as key
extern crate sort_algorithms;
use sort_algorithms::gravity_sort;
fn main() {
let mut arr = vec![9, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
gravity_sort(&mut arr, |&a| a);
println!("{:?}", &arr);
assert_eq!(arr, [ 0, 1, 2, 3, 4, 5, 6, 9]);
}
Can only be used to sort lists of positive integers as key
extern crate sort_algorithms;
use sort_algorithms::counting_sort;
fn main() {
let mut arr = vec![7, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
counting_sort(&mut arr, |&a| a);
println!("{:?}", &arr);
assert_eq!(arr, [0, 1, 2, 3, 4, 5, 6, 7]);
}
extern crate sort_algorithms;
use sort_algorithms::flash_sort;
fn main() {
let mut arr = vec![-1, 6, 5, 2, 4, 3, 1, 0];
println!("{:?}", &arr);
flash_sort(&mut arr, |&a| a);
println!("{:?}", &arr);
assert_eq!(arr, [-1, 0, 1, 2, 3, 4, 5, 6]);
}