You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
662 B
33 lines
662 B
/*
|
|
* 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);
|
|
}
|
|
}
|
|
|
|
}
|