标签:style blog io color ar java for sp div
伪代码:
SELECTION-SORT
1 for i=2 to A.length-1 2 max = A[i] 3 mark = i 4 for j=i+1 to A.length 5 if A[j]>max 6 max=A[j] 7 mark = j 8 A[mark]=A[i] 9 A[i] = max
Java 实现:
public class SelectionSort { public static double [] sort(double [] A) { for(int i = 0; i<A.length-1; i++) { double max = A[i]; int mark = i; for(int j =i+1;j<A.length;j++) if(A[j]>max) { max = A[j]; mark = j; } A[mark] = A[i]; A[i]=max; } return A; } public static void main(String[] args) { double [] A = {1.3, 5 ,2, 6.9, 2.0,7.8,4.3}; A = SelectionSort.sort(A); for(double a:A) System.out.print(a+" "); } }
标签:style blog io color ar java for sp div
原文地址:http://www.cnblogs.com/wzm-xu/p/4077262.html