This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn sleep_sort(arr: &mut [u64]) { | |
let (s, r) = std::sync::mpsc::channel(); | |
for &n in arr { | |
let s = s.clone(); | |
std::thread::spawn(move || { | |
std::thread::sleep(std::time::Duration::from_millis(n)); | |
s.send(n).unwrap(); | |
}); | |
} | |
*arr = r.iter().collect::<Vec<_>>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn monkey_sort<T: Ord>(arr: &mut [T]) { | |
while !is_sorted(arr) { | |
arr.shuffle(&mut rand::thread_rng()); | |
} | |
} |
