Go to Top

Sunday 25 September 2011

Selection Sort Descending

Java Program :

class selsort_d
{
 static void sort(int a[])
 {
     int i,j,c,k;
     for(i=0;i<a.length-1;i++)
     {
         c=i+1;
         for(j=0;j<a.length-1-i;j++)
         {
             if(a[i]<a[c])
             {
                 k=a[c];
                 a[c]=a[i];
                 a[i]=k;
                }
                c++;
            }
        }
        System.out.print("Sorted array : ");
        for(i=0;i<a.length;i++)
        System.out.print(a[i]+" ");

    }
}

8 comments:

ShareThis