Created
September 14, 2024 08:10
-
-
Save ggssh/1f7c9e01c060b3b3f211c486e143e895 to your computer and use it in GitHub Desktop.
Sleep Sort
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<_>>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment