排序算法之简单选择排序

来源:互联网 发布:java写九九乘法表 编辑:程序博客网 时间:2024/05/01 09:16

时间复杂度:平均O(n²)  最好O(n²)  最坏O(n²)

空间复杂度:O(1)

稳定性:不稳定

特点:n小时较好

public class SelectSort {public static void main(String[] args) {int[] a = { 2, 7, 8, 3, 1, 6, 9, 0, 5, 4 };selectSort(a);for (int n : a) {System.out.print(n + " ");}}public static void selectSort(int[] a) {if (a == null) {return;}int i, j;int l = a.length;for (i = 0; i < l - 1; i++) {int min = i;for (j = i + 1; j < l; j++) {if (a[j] < a[min]) {min = j;}}if (min != i) {int temp = a[i];a[i] = a[min];a[min] = temp;}}}}


0 0
原创粉丝点击