I am making a selection sort algorithm in Java.
The logic seems to be perfect, but this code is not sorting the elements.
import java.util.Arrays;
public class selectionsort{
int y;
void swap(int a[], int firstindex, int secondindex){
int temp=a[firstindex];
a[firstindex]=a[secondindex];
a[secondindex]=temp;
}
public void selectionsort1(int a[],int i){
int lowestindex;
for(y=0;y<a.length-2;y++){
lowestindex=selectionsort2(a,y);
swap(a,y,lowestindex);
}
}
public int selectionsort2(int a[],int y){
int setvalue=a[y];
int setindex=y;
for(int x=setindex+1;x<a.length;x++){
if(a[x]<setvalue){
setvalue=a[x];
}
}
return setvalue;
}
public static void main(String args[]){
int[] a={88,28,39,40,15,06,97,80};
int i=0;
int y=0;
selectionsort s1=new selectionsort();
s1.selectionsort1( a, i);
for (int element: a) {
System.out.println(element);
}
}
}
Why doesn't this work?