Sort an array using selection sort
17/10/2013 20:18
public static void main(String args[])
{
int[]a={12,33,1,3,2,5};
int b=a.length;
int max;
int p;
for(int i=0;i<=b-1;i++)
{
max=a[i];
p=i;
for(int j=i+1;j<b;j++)
{
if(a[j]>max)
{
max=a[j];
p=j;
}
}
a[p]=a[i];
a[i]=max;
}
for(int k=0;k<b;k++)
{
System.out.println(a[k]+" ");
}
}
}