
Let us see an example of sorting an array to make the idea of selection sort clearer.
Example. Sort {5, 1, 12, -5, 16, 2, 12, 14} using selection sort.
![]() |
Example 1 (http://www.algolist.net/Algorithms/Sorting/Selection_sort) |
Example: Selection Sort in Java
When you run the program, the output will be:
Enter the array size:
3
Enter the array elements:
4
12
1
Before Sorted :Array Elements:
4 12 1
After Sorted :Array Elements:
1 4 12