Skip to content

Commit

Permalink
sorts: Make selection sort generic
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 15, 2023
1 parent beedec6 commit 7822e29
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sorts/src/selection_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
///
/// 即使输入数据已经是排好序的, 该算法依然需要 N^2 次的操作.
/// N^2 / 2 次比较以及 N 次交换.
pub fn selection_sort(list: &mut [i32]) {
pub fn selection_sort<T>(list: &mut [T])
where
T: PartialOrd,
{
if list.is_empty() {
return;
}
Expand Down

0 comments on commit 7822e29

Please sign in to comment.