编程语言
首页 > 编程语言> > 选择排序java实现

选择排序java实现

作者:互联网

package text.algorithm;

/**
* 选择排序
* O(n^2);空间复杂度O(1);
*/
public class SelectionSort {

public static void selectionSort(int[] a) {
for (int i = 0; i < a.length; i++) {
int k = a[i];
for (int j = i+1; j < a.length; j++) {
if(k>a[j]){
int b = k;
k = a[j];
a[j]=b;
}
}
a[i]=k;
}
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+",");
}
}

public static void main(String[] args) {
int[] a = {1,23,43,56,34,12,56,7,87,-56,34,2};
selectionSort(a);
}
}

标签:java,selectionSort,int,56,选择,++,length,排序,public
来源: https://www.cnblogs.com/MisMe/p/10693175.html