Skip to content

Commit 978aed9

Browse files
authored
rewrite sort as sort_unstable where applicable in exercise examples (#1015)
1 parent 76508e3 commit 978aed9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

exercises/anagram/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashSet;
22

33
fn sort(word: &str) -> String {
44
let mut sorted: Vec<char> = word.chars().collect();
5-
sorted.sort();
5+
sorted.sort_unstable();
66
sorted.into_iter().collect()
77
}
88

exercises/grade-school/example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ impl School {
1414
pub fn add(&mut self, grade: u32, student: &str) {
1515
let entry = self.grades.entry(grade).or_insert_with(Vec::new);
1616
entry.push(student.to_string());
17-
entry.sort();
17+
entry.sort_unstable();
1818
}
1919

2020
pub fn grades(&self) -> Vec<u32> {
2121
let mut s = self.grades.keys().cloned().collect::<Vec<u32>>();
22-
s.sort();
22+
s.sort_unstable();
2323
s
2424
}
2525

exercises/high-scores/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'a> HighScores<'a> {
2222

2323
pub fn personal_top_three(&self) -> Vec<u32> {
2424
let mut sorted = self.scores.to_vec();
25-
sorted.sort();
25+
sorted.sort_unstable();
2626
sorted.reverse();
2727
sorted.truncate(3);
2828
sorted

0 commit comments

Comments
 (0)