Wednesday, January 16, 2008

Sort an array using selection sort technique

import java.io.*;
class SelectionSort
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 Integer values ");
for(int i=0;i<10;i++)
{
x[i] = Integer.parseInt(br.readLine());
}
int h,p=0;
for(int i=0;i{
h=x[i];
for(int j=i;j{
if(x[j]>h)
{
h=x[j];
p=j;
}
}
x[p]=x[i];
x[i]=h;
}
System.out.println(" After Sorting");
for(int i =0;i<=x.length-1;i++)
{
System.out.println(x[i]);
}
}
}

2 comments:

Allen Alex said...

import java.io.*;
class SelectionSort
{
public static void main(String args[])throws IOException
{
int x[]=new int[10];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter 10 Integer values ");
for(int i=0;i<10;i++)
{
x[i] = Integer.parseInt(br.readLine());
}
int h,p=0;
for(int i=0;i{
h=x[i];
for(int j=i;j{
if(x[j]>h)
{
h=x[j];
p=j;
}
}
x[p]=x[i];
x[i]=h;
}
System.out.println(" After Sorting");
for(int i =0;i<=x.length-1;i++)
{
System.out.println(x[i]);
}
}
}

Allen Alex said...

dt is d correct procedure man!!!!!