![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRPQPOQ5FfR359dzPMY1FWxq-5WUQxj6mLgnFUqV9waHn8FEIY2Azit7fT8pU2Do1NL5vgi5rc1_dUkMFme4XX_K5YHnknfVAcHDOL76pBx0BB4rFb1f6T5KiuBCnsCdnZLtJ7tQ6nYtX5/s200/%25233.png)
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