SHARE
TWEET

Untitled

a guest Aug 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Author Bill Wood
  2. // uses nightly-only feature slice_patterns
  3. #![feature(slice_patterns)]
  4. fn main() {
  5.     let x = vec!(1,2,3,2,5,8,4,9,);
  6.     println!("{:?}", stalin_sort(x));
  7.     let x = vec!('a','b','c','b','e','g','d','x');
  8.     println!("{:?}", stalin_sort(x));
  9.     let ideologies = vec!(
  10.         "Fully Automated Luxury Space Communism",
  11.         "Socialism",
  12.         "Capitalism",
  13.         "Communism",
  14.     );
  15.     println!("{:?}", stalin_sort(ideologies));
  16. }
  17.  
  18. fn stalin_sort<T: PartialOrd>(mut v: Vec<T>) -> Vec<T> {
  19.     match &v[..] {
  20.         [] | [_] => v,
  21.         [x, y, ..] if x <= y => {
  22.                 let rest = v.split_off(1);
  23.                 v.append(&mut stalin_sort(rest));
  24.                 v
  25.             }
  26.         _ => {
  27.                 v.remove(1);
  28.                 stalin_sort(v)
  29.             }
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top