I’m studying for my master’s degree at the moment and in my spare time I rebuilt some of the basic sorting algorithms I learned. There are many more, but I wrote a few of them to gain some insight and because it’s fun :). The algorithms are far from optimized for real-life usage, but the mechanics are correct.
I built the following algorithms:
- Bubble sort
- Insertion sort
- Merge sort
- Quicksort with median 3
- Randomized Quicksort
All the algorithms are built in such a way that they can sort any object type. To make this possible I used delegates to pass to the algorithms so they can extract the properties of the object that you need to sort on. To show how it works I’ve added a testing solution. It’s a simple console application that sorts arrays of given size and times how long it takes the algorithm to finish.
The source code can be found on Github, or in the downloads (top navigation bar).
If you have any questions, comments are open! 🙂