Sorting algorithms/Bogosort: Difference between revisions

→‎{{header|Rust}}: Made calls a little more intuitive
(→‎{{header|Rust}}: Made calls a little more intuitive)
Line 2,200:
use rand::Rng;
 
fn bogosortbogosort_by<T,F>(order: F, coll: &mut [T], order: F)
where F: Fn(&T, &T) -> bool
{
let mut rng = rand::thread_rng();
while !is_sorted(coll, &order, coll) {
rng.shuffle(coll);
}
}
 
#[inline]
fn is_sortedis_sorted_by<T,F>(order: F, coll: &[T], order: F) -> bool
where F: Fn(&T,&T) -> bool,
{
Line 2,218 ⟶ 2,219:
fn main() {
let mut testlist = [1,55,88,24,990876,312,67,0,854,13,4,7];
bogosortbogosort_by(&mut testlist, |x,y| x < y, &mut testlist);
println!("{:?}", testlist)
bogosortbogosort_by(&mut testlist, |x,y| x > y, &mut testlist);
println!("{:?}", testlist);
}