Java Reference
In-Depth Information
Sorting
num
in ascending order using selection sort proceeds as follows:
1
st
pass
•
Find the smallest number in the entire list, from positions
0
to
6
; the smallest is
15
,
found in position
4
.
Interchange the numbers in positions
•
0
and
4
. This gives us the following:
2
nd
pass
•
Find the smallest number in positions
1
to
6
; the smallest is
33
, found in position
5
.
•
Interchange the numbers in positions
1
and
5
. This gives us the following:
3
rd
pass
2
to
6
; the smallest is
48
, found in position
5
.
•
Find the smallest number in positions
2
and
5
. This gives us the following:
•
Interchange the numbers in positions
4
th
pass
•
Find the smallest number in positions
3
to
6
; the smallest is
52
, found in position
6
.
•
Interchange the numbers in positions
3
and
6
. This gives us the following:
5
th
pass
4
to
6
; the smallest is
57
, found in position
4
.
•
Find the smallest number in positions
4
and
4
. This gives us the following:
•
Interchange the numbers in positions
Search WWH ::
Custom Search