💩

programierds

algorithms / sorting

Selection Sort
Step by Step

Find the smallest element in the unsorted part and swap it with the first unsorted position.

C Implementation Line: -
1int arr[] = {29, 10, 14, 37, 13};
2int n = 5;
3for (int i = 0; i < n - 1; i++) {
4  int min_idx = i;
5  for (int j = i + 1; j < n; j++) {
6    if (arr[j] < arr[min_idx]) {
7      min_idx = j;
8    }
9  }
10  int temp = arr[min_idx];
11  arr[min_idx] = arr[i];
12  arr[i] = temp;
13}
i -
j -
min_idx -
Array Visualization
Click "Start" to begin.
Paso 0 / 0
← Back to all presentations