competitive-programming-lib 0.1.0

Competitive Programming Library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use rand::seq::SliceRandom;

pub fn bogo_sort(arr: &mut [i32]) {
    let mut rng = rand::thread_rng();
    while !is_sorted(arr) {
        arr.shuffle(&mut rng);
    }
}

fn is_sorted(arr: &[i32]) -> bool {
    for i in 1..arr.len() {
        if arr[i] < arr[i - 1] {
            return false;
        }
    }
    true
}