enumのリストで書いてみたわ
rust不慣れだから所々おかしいかも
https://ideone.com/0Ro48L
enum List<T> {
Cons(T, Box<List<T>>),
Nil,
}
impl<T: Copy + PartialOrd> List<T> {
// 略
fn qsort(&self) -> Self {
match self {
List::Nil => List::Nil,
List::Cons(pivot, tail) => {
let (smaller, rest) = tail.partition(|x| *x < *pivot);
smaller.qsort().concat(&rest.qsort().prepend(*pivot))
}
}
}
}
fn main() {
let list = List::<i32>::nil().prepend(4).prepend(8).prepend(8).prepend(3).rev();
list.each(|n| print!("{}", n));println!("");
list.qsort().each(|n| print!("{}", n));println!("");
}