March 2018
Intermediate to advanced
272 pages
7h 4m
English
There is also an interesting place where some gains can be made. Usually, when you want to sort a vector, for example, stable sorting is used. This means that if two elements have the same ordering, the original ordering will be preserved. Let's see it with an example. Suppose we have a list of fruits we want to order alphabetically, taking into account only their first letter:
let mut fruits = vec![ "Orange", "Pome", "Peach", "Banana", "Kiwi", "Pear" ]; fruits.sort_by(|a, b| a.chars().next().cmp(&b.chars().next())); println!("{:?}", fruits);
This will print exactly the following:
And in that order. Even though Peach and ...
Read now
Unlock full access