public class Sort {
private int [] a;
public void setA(int[] a) {
this.a = a;
}
private static int minArr(int[]a ,int x){
int min=a[x];
int p=x;
for(int y=x;y<a.length;y++){
if(min>a[y]){
min=a[y];
p=y;
}
}
return p;
}
public void arrSort(){
int k=0;
for(int i=0;i<a.length;i++){
int y= minArr(a,i);
if(y!=i){
int temp=a[i];
a[i]=a[y];
a[y]=temp;
k++;
System.out.println(k);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int []a={5,3,2,6,4,9,7,0};
Sort sort=new Sort();
sort.setA(a);
sort.arrSort();
for(int x:a){
System.out.print(x);
}
System.out.println();
}
}
|