Sort your life out!

- 1 minute read

These days I am reviewing sorting algorithms and I have created a class in C# that allows you to sort in ascending order an array of integers.

I once read that there are no sort methods, only elements to sort, so this class has 5 static methods that implement the 5 different types of most common sorting algorithms: Insert, Select, Bubble, Shell and QuickSort. All algorithms sort an array of integers, although floats or characters could perfectly well be used.

The QuickSort algorithm performs best for any number of elements. The Select algorithm is relatively fast for sorting a small number of elements. Finally, BubbleSort is the simplest algorithm to implement but the worst performing. It is relatively useful for sorting a small number of elements, but the sorting time grows exponentially as the array size increases.

You can download the class file (SortArray.cs) from here.