![$\displaystyle \underbrace{A[1] A[2] \space \cdots \space A[i-1]}_{\begin{array}{l}\mbox{sorted as in the}\\\mbox{final sequence}\end{array}}^{}\,$](img456.gif)
![$\displaystyle \underbrace{A[i] \space \cdots \space A[n]}_{\begin{array}{l}\mb......lect least among these}\\\mbox{and swap with} \space \ A[i]\end{array}}^{}\,$](img457.gif)
![$\displaystyle \underbrace{A[1] A[2] \space \cdots \space A[i]}_{\begin{array}{l}\mbox{sorted as in }\\\mbox{final sequence}\end{array}}^{}\,$](img458.gif)
![$\displaystyle \underbrace{A[i+1] \space \cdots \space A[n]}_{\begin{array}{l}\mbox{yet to be sorted}\end{array}}^{}\,$](img459.gif)
for(i
= 1, i
n
- 1;i + +)
{
lowindex = i; lowkey = A[i]
key;
for(j = i +
1;j
n;j
+ +)
if (A[j]
key < lowkey)
{
lowkey = A[j]
key;
lowindex = j
}
swap (A[i], A[lowindex])
}
}
