class selectionSort
{
public static void main(String args[])
{
int x[]={2,4,6,3,8};
for (int i=0; i<x.length-1; i++)
{
for (int j=i+1; j<x.length; j++)
{
if (x[i] > x[j])
{
//... Exchange elements
int temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
System.out.print("Sorted Array:");
for(int i=0;i<x.length;i++)
System.out.print("\t" +x[i]);
}
}
{
public static void main(String args[])
{
int x[]={2,4,6,3,8};
for (int i=0; i<x.length-1; i++)
{
for (int j=i+1; j<x.length; j++)
{
if (x[i] > x[j])
{
//... Exchange elements
int temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
System.out.print("Sorted Array:");
for(int i=0;i<x.length;i++)
System.out.print("\t" +x[i]);
}
}
No comments:
Post a Comment