selection sort optimization

This commit is contained in:
shellhub 2021-04-12 16:24:11 +08:00
parent 156f7a67f4
commit dba60f03ae

View File

@ -45,7 +45,9 @@ public class Selection<T extends Comparable<T>> extends Sort<T> {
min = j;
}
}
swap(nums, i, min);
if (min != i) {
swap(nums, i, min);
}
}
}
}