Q:

How to implement selection sort? 

I have the following code snippet..
public void selsort()
{
    int j=0,i,k; int low;
    for(k = 0; k < ele; k++)
    {
        for(i = j;i < ele; i++)
            if(a[i] < a[i+1])
                low = i;
        if(i!=j)
        {
            long temp=a[j];
            a[j]=a[i];
            a[i]=temp;
        }
        j++;
    }
}

I don't know why the above algorithm is not working properly. 
What has to be modified to get it working properly? 

A:

fixed your code
public void selsort() {
    int j = 0, i, k;
    int low;
    for (k = 0; k < ele; k++) {
        low = j;
        for (i = j; i < ele; i++)
            if (a[i] < a[low]) {
                low = i;
            }
        if (j ! = low) {
            int temp = a[j];
            a[j] = a[low];
            a[low] = temp;
        }
        j++;
    }
}

but can be used k insdead of j, and better have input params instead using class fields like a and ele

