rust - How can I sort a LinkedList with just the standard library? -
vec
provides sort method (through deref
implementation), linkedlist
not. there generic algorithm somewhere in rust standard library allows sorting of linkedlist
s?
i don't think there built-in way it. however, can move list contents vec
, sort , turn linked list:
let mut vec: vec<_> = list.into_iter().collect(); vec.sort(); let list: linkedlist<_> = vec.into_iter().collect();
this idea not remotely bad may seem - see here. while relatively fast algorithms sorting linked list do exist, won't give of cache performance flat array sorting may do.
Comments
Post a Comment