Selection sort is said to be an efficient algorithm when considering small computations involving limited memory/resource but it is quite inefficient when compared to other techniques when huge computations are required.Selection sort is said to be efficient for small list of items because of its simplicity.
The following steps Explains the working of the Selection sort Algorithm
- Obtain the Item with the Minimal value from a List/Collection of items
- Swap the item with the Item in the first position of the Collection/List
- Repeat the Process for the rest of the Items in the Collection
The Following is the Complete Program Source Code in Java for Implementing Selection Sort Algorithm
import java.io.*;
import java.lang.*;
class array
{
DataInputStream get;
int a[];
int i,j,n;
void getdata()
{
try
{
get=new DataInputStream(System.in);
System.out.println("Enter the limit");
n=Integer.parseInt(get.readLine());
a=new int[n];
System.out.println("Enter the elements in the array");
for(i=0;ia[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println("Elements in ascending order is:");
for(i=0;i=0;i--)
System.out.print(" "+a[i]);
}
}
class selectionsort
{
public static void main(String arg[])
{
array obj=new array();
obj.getdata();
obj.sorting();
}
}
No comments:
Post a Comment