Content deleted Content added
No edit summary Tags: Reverted section blanking Mobile edit Mobile web edit |
Undid revision 1081094688 by 95.74.37.32 (talk) |
||
Line 75:
11 12 22 25 64
</pre>
== Implementations ==
{{unreferenced section|date=May 2019}}
Below is an implementation in [[C (programming language)|C]].
<syntaxhighlight lang="c" style="overflow:auto; width:auto;" line="1">
/* a[0] to a[aLength-1] is the array to sort */
int i,j;
int aLength; // initialise to a's length
/* advance the position through the entire array */
/* (could do i < aLength-1 because single element is also min element) */
for (i = 0; i < aLength-1; i++)
{
/* find the min element in the unsorted a[i .. aLength-1] */
/* assume the min is the first element */
int jMin = i;
/* test against elements after i to find the smallest */
for (j = i+1; j < aLength; j++)
{
/* if this element is less, then it is the new minimum */
if (a[j] < a[jMin])
{
/* found new minimum; remember its index */
jMin = j;
}
}
if (jMin != i)
{
swap(a[i], a[jMin]);
}
}
</syntaxhighlight>
== Complexity ==
|