COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Sorting and Searching Algorithms SelectionSort Program BinarySearch Program QuickSort Program HardwareStore Program HardwareStore Comparable Objects Program



SelectionSort Program


Description

This program uses the selection sort algorithm to sort an array of random integers.

Associated Concepts:

Selection Sort

Algorithm:

main method:

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.

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.

Source Code



Sample Run



Video