Selection Sort sorts an array of items by remembering the smallest element in the unsorted region and swaps it with the beginning element of the unsorted region.
Analysis
See 202202220937
Implementation
Note: The following algorithm sorts item in ascending order.
void SelectionSort(ElementType A[], int N) {
int Min;
for (int i = 0; i < N - 1; i++) {
Min = i;
for (int j = i + 1; j < N; j++)
if (Min < A[j])
Min = j
Swap(A[i], A[Min]);
}
}