Title

JAVA

      In this blog, you will find programs on JAVA and also some help on how to write programs for JAVA...

December 18, 2014

Selection Sort



public class SSort
{
   public static void main()
   {
       int a[]={12,45,34,23,1,3,2,7,98};
       for(int x=0; x<a.length-1; x++)
       {
           int l=a[x], pos=x;
           for(int y=x+1;y<a.length;y++)
           {
               if(a[y]<l)
               {
                   l=a[y];
                   pos=y;
               }
           }
           if(x != pos)
           {
               int temp=a[x];
               a[x]=a[pos];
               a[pos]=temp;
           }
       }
       for(int x=0; x<a.length; x++)
           System.out.println(a[x]);
   }
}

No comments:

Post a Comment

Please write your comment in the box below...