Follow The Following Pseudo Code :
MIN(A, K, N, LOC)
An Array A is in memory. This procedure finds the location LOC of the smallest element among A[K], A[K+1],...,A[N]
1. Set MIN :=A[K] AND LOC := K. [Initializes pointers.]
2. Repeat for J=K+1, K+2,...,N:
If MIN>A[J], then: Set MIN :=A[J] and LOC :=A[J] and LOC := J. [End of Loop]
What is the function of procedure 2?
1. Repeat Steps 2 and 3 for K=1,2,...,N-1:
2. Call MIN(A,K,N,LOC).
3. [Intrechange A[K] and A[LOC].]
Set TEMP := A[K], A[K]:=A[LOC] and A[LOC]:=TEMP.
[End of step 1 loop]