A Sabrina, unica vera mia grande passione.
Tech misc‎ > ‎

QuickSort C#

QuickSort algorithm written in C# (plus 2-dimension matrix sorting and multi-column sorting).


Based on John Watson quicksort code (http://watson-net.com/).


Sort methods:

String vector quicksortpublic static void qSort(String[] aData, int iLb, int iUb, int maxStack)
2-dimension matrix of string quicksortpublic static void qSort2(String[,] matrix, int iIdx, int iLb, int iUb, int maxStack)
Multi column sorter (on 2-dim matrix)public static void multiColumnSort(String[,] matrix,int[] orderColumns, int fromRow, int toRow, int maxStack)
Notes: 
- every method can generate a QuickSortException
- in multiColumnSort a orderColumns={5,2,8} is logically equivalent to SQL "Order BY Column#5,Column#2,Column#8"


Example: QuickSorter.multiColumnSort(matrix,new int[]{3,2,1},0,matrix.GetLength(0)-1,32); 
	Original matrix:
	------------------------------------------------
	| Ugo       | IGB Ltd    | New York    | USA   |
	| Carla     | Qwerty srl | Milano      | Italy |
	| Davide    | Qwerty srl | Milano      | Italy |
	| Domenico  | Zsoft srl  | Roma        | Italy |
	| Eleonora  | FH Spa     | Torino      | Italy |
	| Ernesto   | Fish Ltd   | Los Angeles | USA   |
	| Fabrizio  | FH SpA     | Torino      | Italy |
	| Giovanna  | KYZ spa    | Roma        | Italy |
	| Giovanni  | Petrol Ltd | Dallas      | USA   |
	| Giovanni  | Polpol spa | Milano      | Italy |
	| Luca      | Zsoft srl  | Roma        | Italy |
	| Massimo   | IGB Ltd    | New York    | USA   |
	| Raffaella | RFG spa    | Milano      | Italy |
	| Renato    | Qwerty srl | Milano      | Italy |
	| Sabrina   | Sabry SpA  | Torino      | Italy |
	| Sandro    | Zsoft srl  | Roma        | Italy |
	------------------------------------------------

	Sorted matrix:
	------------------------------------------------
	| Giovanni  | Polpol spa | Milano      | Italy | 
	| Davide    | Qwerty srl | Milano      | Italy | 
	| Carla     | Qwerty srl | Milano      | Italy | 
	| Renato    | Qwerty srl | Milano      | Italy | 
	| Raffaella | RFG spa    | Milano      | Italy | 
	| Giovanna  | KYZ spa    | Roma        | Italy | 
	| Domenico  | Zsoft srl  | Roma        | Italy | 
	| Sandro    | Zsoft srl  | Roma        | Italy | 
	| Luca      | Zsoft srl  | Roma        | Italy | 
	| Fabrizio  | FH SpA     | Torino      | Italy | 
	| Eleonora  | FH Spa     | Torino      | Italy | 
	| Sabrina   | Sabry SpA  | Torino      | Italy | 
	| Giovanni  | Petrol Ltd | Dallas      | USA   | 
	| Ernesto   | Fish Ltd   | Los Angeles | USA   | 
	| Massimo   | IGB Ltd    | New York    | USA   | 
	| Ugo       | IGB Ltd    | New York    | USA   | 
	------------------------------------------------

Č
ċ
ď
QuickSort_Csharp.0.2.zip
(5k)
Fabrizio Accatino,
03/gen/2010 06:28