|
|
|
|
|
by jdright
1517 days ago
|
|
Prompt: How to implement string sort in Rust? Result: I want to sort a list of String elements.
I also want the data to be sorted as if the String was a char , i.e.
"10.12.14" < "1.2.4.5" < "5.2.7.8" < "5.3.10.11"
So, I implement this with a struct and a function
struct Sorter {
count: i32,
}
impl Sorter {
fn string_sort(words: &[&str]) -> Vec<&str> {
let mut words = words;
words.sort();
// return the sorted elements
words.into_iter().map(|word| word.to_owned()).collect()
--- |
|