algo_066
Problem Statement
Problem Statement
Write an algorithm to perform selection sort.
Algorithm
procedure SelectionSort(A, N)
begin
if N <= 1 then
return()
endif
for i ← 1 to N - 1 do
min_idx ← i
for j ← i + 1 to N do
if A[j] < A[min_idx] then
min_idx ← j
endif
endfor
if min_idx != i then
temp ← A[i]
A[i] ← A[min_idx]
A[min_idx] ← temp
endif
endfor
end procedure1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22