competitive_programming_lib/Sorting/
bogo_sort.rs1use rand::seq::SliceRandom;
2
3pub fn bogo_sort(arr: &mut [i32]) {
4 let mut rng = rand::thread_rng();
5 while !is_sorted(arr) {
6 arr.shuffle(&mut rng);
7 }
8}
9
10fn is_sorted(arr: &[i32]) -> bool {
11 for i in 1..arr.len() {
12 if arr[i] < arr[i - 1] {
13 return false;
14 }
15 }
16 true
17}