Java Program :
class selsort_a
{
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]+" ");
}
}
class selsort_a
{
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]+" ");
}
}
it's bubble sort not selection sort
ReplyDeleteMan its bubblbubble sort not selection sort
ReplyDelete