Select Sort Description
The basic idea is to first find the smallest (or largest) element in an unordered sequence, and then store it in the beginning of the sequence, and then continue looking for the smallest (or largest) element from the remaining unsorted elements, and then place it at the end of the sorted sequence. And so on until all elements are sorted.
Select Sort Code
/*
* Select sort
* Parameter Description
* A----with sorted array
* N----Array length
*/
void Select_sort (int a[], int n)
{
int i;//The end position of the ordered area
int j;//The end position of the unordered area
int min;//unordered area min element position
for (i=0;i<n;i++)
{
Min=i;
Find the smallest element between a[i-1]....a[n-1] and assign a value to min.
for (j=i+1;j<n;j++)
{
if (A[j]<a[min])
{
Min=j;
}//end of If
}//End of For2
If min!=i, then Exchange A[i] and A[min]
if (min!=i)
{
Swap (a[i],a[min]);
}//End of If
}
}
Time Complexity of O (N2)
Sorting algorithm Selection