Implementation (Part 2)
Lesson 6 of 9 in Coddy's Selection Sort - DSA Series course.
Let's turn the single pass into a full sort.
Challenge
EasyNow let's complete the algorithm.
Extend your selectionSort function so it sorts the entire array in ascending order and returns it.
Repeat the "find the smallest and swap it into place" step for every position: for each index i, find the smallest element in the unsorted part (from i to the end) and swap it into position i.
Use the previous lesson and the pseudocode as a reference :)
Try it yourself
#include <stdlib.h>
int* selectionSort(int* arr, int arr_size, int* returnSize) {
// Write code here
*returnSize = arr_size;
return arr;
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Selection Sort - DSA Series
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)