Sorting algorithms

If you need some efficient sorting algorithm wrapped in a generic method, C5 has some in store for you. It has three sorting algorithms exposed as static methods of the class Sorting, which are as follows:

  • IntroSort
  • HeapSort
  • InsertionSort

All these sorting mechanisms operate on an array of T, and all of these algorithms operate in-place. This means once you operate them on an array, you will be left with the sorted array and will lose the original unsorted array. We can use them to sort different collections as follows:

Pattern 1: Sorting an array of integers

IntroSort is an unstable version of QuickSort that can be used in situations where QuickSort fails to offer high performance, such as in the case of almost sorted collections. ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.