Exchange Selection Sort

import java.io.*;
class SelectionSort
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);

int ARR[]=new int[10];
int i,j,temp,sml,pos;

System.out.println(“Enter 10 numbers in an array”);
for(i=0;i<10;i++)
{
ARR[i]=Integer.parseInt(y.readLine());
}

for(i=0;i<9;i++)
{
sml=ARR[i];
pos=i;
for(j=i+1;j<10;j++)
{
if(ARR[j]<sml)
{
sml=ARR[j];
pos=j;
}
temp=ARR[i];
ARR[i]=sml;
ARR[pos]=temp;
}
}

System.out.println(“The sorted array is :”);
for(i=0;i<10;i++)
{
System.out.println(ARR[i]);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s