Tag Archives: sorting

Compare sorting algorithms in C#, article 5 of 5

Countingsort The discussion of Quicksort in my previous post mentions that the fastest possible sorting algorithms that use comparisons take on the order of N * log(N) steps. Countingsort does not use comparisons so it is not bound by that … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare sorting algorithms in C#, part 4 of 5

Quicksort Quicksort is a recursive algorithm that uses a divide-and-conquer technique. While the list of items to be sorted contains at least two items, Quicksort divides it into two sublists and recursively calls itself to sort the sublists. The Quicksort … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , | Leave a comment

Compare sorting algorithms in C#, part 3 of 5

Selectionsort Selectionsort is a very simple algorithm. First you search the list for the smallest item. Then you swap that item with the item at the top of the list. Next you find the second smallest item and swap it … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare sorting algorithms in C#, part 2 of 5

Bubblesort Bubblesort is a specialized algorithm designed for sorting items that are already mostly in sorted order. If only one or two items in your list are out of order, Bubblesort is very fast. If the items in your list … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare sorting algorithms in C#, post 1 of 5

This post begins a series of articles about sorting algorithms. Much of the text originally appeared in the December 1995 issue of Visual Basic Developer magazine, a publication that seems to no longer exist. All of these posts include the … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | 6 Comments

Use a custom sort order for ListBox or ComboBox items in C#

If you set a ComboBox and ListBox control’s Sorted property to true, the control sorts the items it contains. Unfortunately it sorts the items alphabetically. That means if the items are strings that begin with Roman numerals, they may be … Continue reading

Posted in algorithms, controls, user interface | Tagged , , , , , , , , , , , , , , , | 2 Comments

Sort ListBox or ComboBox items in numeric order in C#

If you set a ListBox control’s Sorted property to true, the control sorts its contents. Unfortunately it can only sort its contents in alphabetic order. If the items are numeric, that may not be what you want. This example sorts … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | Leave a comment

Sort and search arrays in C#

The Array class provides several useful methods for working with arrays. Two of them let you sort and search arrays. The following code shows how the program uses the Array class’s Sort method to sort an array of random data. … Continue reading

Posted in algorithms, arrays | Tagged , , , , , , , , , , , | Leave a comment

Sort objects in C#

This example shows how you can easily sort objects in C#. Sorting algorithms are absolutely fascinating and I recommend that everyone study them at some point. Different algorithms demonstrate interesting and useful techniques such as recursion, divide-and-conquer, linked data structures, … Continue reading

Posted in algorithms | Tagged , , , , , , , , , , , , , , | Leave a comment