SelectionSort Program
Description
This program uses the selection sort algorithm to sort an array of random integers.Associated Concepts:
Selection Sort
Algorithm:
main method:
selectionSort method definition:
Create an array with random integers.
Print the unsorted array elements.
Call the method selectionSort() to sort the array, and pass the array as the argument.
Print the sorted array elements.
Print the unsorted array elements.
Call the method selectionSort() to sort the array, and pass the array as the argument.
Print the sorted array elements.
selectionSort method definition:
Find the smallest element in the array.
Exchange it with the element in the first position.
Find the 2nd smallest element.
Exchange it with the element in the 2nd position.
…
The process continues until the entire array is sorted.
Exchange it with the element in the first position.
Find the 2nd smallest element.
Exchange it with the element in the 2nd position.
…
The process continues until the entire array is sorted.