.NET Implementation of the quicksort algorthm on various arrays.
Hi All,
Here is a simple class to sort an array of char, integer, or strings using the quicksort algorithm, which works very fast on large groups of items, in the manner described below:
Originally Posted by http://linux.wku.edu/~lamonml/algor/sort/quick.html
The recursive algorithm consists of four steps (which closely resemble the merge sort):
1. If there are one or less elements in the array to be sorted, return immediately.
2. Pick an element in the array to serve as a "pivot" point. (Usually the left-most element in the array is used.)
3. Split the array into two parts - one with elements larger than the pivot and the other with elements smaller than the pivot.
4. Recursively repeat the algorithm for both halves of the original array.
I didn't come up with this method, but it works great. Attatched is a .NET Project to build the DLL, as well as a precompiled DLL with Documentation. The method is called using the following:
VB Code:
ArrayVariable = QuickSort(ArrayVariableName, [i]Ascending as Boolean(Optional)[/i])
There are 6 overloads, two each for char, string, and integer. (With the option to use descending order as an available overload for each). XML Comments are used, and pre-compiled by the NDoc Documentation tool , and tested inside VS 2003.
I mostly did this as a self learning experience, with sorting, and overloads, and XML commenting, but feel free to use it if you can, bash it if you must, and ignore it in all likelyhood
Re: .NET Implementation of the quicksort algorthm on various arrays.
Well Like I said, this was a learning experience. The Icomparable Interface and the Array.Sort method are about 7 times faster. Now, I get to learn interfaces Still, i'll leave it up, as I suppose it's not AWFUL coding or anything