parent
2906c009b4
commit
aee03ba608
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package sort;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author User
|
||||
*/
|
||||
public class SelectionSort {
|
||||
|
||||
private static void exch(int[] a,int i,int j){
|
||||
int t=a[i];
|
||||
a[i]=a[j];
|
||||
a[j]=t;
|
||||
}
|
||||
public void sort(int[] a){
|
||||
int N=a.length;
|
||||
for(int i=0;i<N;i++){
|
||||
int min=i;
|
||||
for(int j=i+1;j<N;j++){
|
||||
if(a[j]<a[min]){
|
||||
min=j;
|
||||
}
|
||||
}
|
||||
exch(a,i,min);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue