import java.io.*;
class selectionsort
{
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=0,i,j,t;
int a[] = new int[10];
System.out.println("Enter size of the array:");
try
{
n= Integer.parseInt(br.readLine());
}
catch(Exception e) { }
System.out.println("Enter elements into the array:");
try
{
for(i=0;i<n;i++)
a[i] = Integer.parseInt(br.readLine());
}
catch(Exception e) { }
i=0;
while(i<n-1)
{
int key=i;
for(j=i+1;j<n;j++)
{
if(a[j]<a[key])
{
key=j;
}
}
t=a[key];
a[key]=a[i];
a[i]=t;
i++;
}
System.out.println("The sorted array is :");
for(i=0;i<n;i++)
System.out.println(a[i]);
}
}
class selectionsort
{
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=0,i,j,t;
int a[] = new int[10];
System.out.println("Enter size of the array:");
try
{
n= Integer.parseInt(br.readLine());
}
catch(Exception e) { }
System.out.println("Enter elements into the array:");
try
{
for(i=0;i<n;i++)
a[i] = Integer.parseInt(br.readLine());
}
catch(Exception e) { }
i=0;
while(i<n-1)
{
int key=i;
for(j=i+1;j<n;j++)
{
if(a[j]<a[key])
{
key=j;
}
}
t=a[key];
a[key]=a[i];
a[i]=t;
i++;
}
System.out.println("The sorted array is :");
for(i=0;i<n;i++)
System.out.println(a[i]);
}
}
No comments:
Post a Comment