This is the code:
public enum ColumnType{
DateTime,
Int,
String,
}
public sealed class Sorter
{
public static void Sort(ref ArrayList tabel, SortOrder s, ColumnType t, int
colomn)
{
QuickSort(ref tabel, ref s, ref t, ref colomn, 0, tabel.Count - 1);
}
private static void QuickSort (ref ArrayList szArray, ref SortOrder s, ref
ColumnType t, ref int column, int nLower, int nUpper)
{
if (nLower < nUpper)
{
int nSplit = Partition (ref szArray, ref s, ref t, ref column, nLower,
nUpper);
QuickSort (ref szArray, ref s, ref t, ref column, nLower, nSplit - 1);
QuickSort (ref szArray, ref s, ref t, ref column, nSplit + 1, nUpper);
}
}
private static int Partition (ref ArrayList szArray, ref SortOrder s, ref
ColumnType t, ref int column, int nLower, int nUpper)
{
int nLeft = nLower + 1;
string[] szPivot = (string[]) szArray[nLower];
int nRight = nUpper;
string[] szSwap;
while (nLeft <= nRight)
{
switch(t)
{
case ColumnType.String:
#region "string"
switch(s)
{
case SortOrder.Ascending:
while (nLeft <= nRight)
{
if ( ((string[])szArray[nLeft])[column].CompareTo (szPivot[column]) > 0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
if ( ((string[])szArray[nRight])[column].CompareTo (szPivot[column]) <= 0)
break;
nRight = nRight - 1;
}
break;
case SortOrder.Descending:
while (nLeft <= nRight)
{
if ( ((string[])szArray[nLeft])[column].CompareTo (szPivot[column]) <= 0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
if ( ((string[])szArray[nRight])[column].CompareTo (szPivot[column]) > 0)
break;
nRight = nRight - 1;
}
break;
}
break;
#endregion
case ColumnType.Int:
#region "int"
switch(s)
{
case SortOrder.Ascending:
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nLeft];
if (
Convert.ToInt32(tmp[column]).CompareTo(Convert.ToInt32(szPivot[column])) >
0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nRight];
if (Convert.ToInt32(tmp[column]).CompareTo(Convert.ToInt32(szPivot[column]))
<= 0)
break;
nRight = nRight - 1;
}
break;
case SortOrder.Descending:
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nLeft];
if (
Convert.ToInt32(tmp[column]).CompareTo(Convert.ToInt32(szPivot[column])) <=
0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nRight];
if (Convert.ToInt32(tmp[column]).CompareTo(Convert.ToInt32(szPivot[column]))
break;
nRight = nRight - 1;
}
break;
}
break;
#endregion
case ColumnType.DateTime:
#region "DateTime"
switch(s)
{
case SortOrder.Ascending:
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nLeft];
if (
Convert.ToDateTime(tmp[column]).CompareTo(Convert.ToDateTime(szPivot[column]
)) > 0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nRight];
if
(Convert.ToDateTime(tmp[column]).CompareTo(Convert.ToDateTime(szPivot[column
])) <= 0)
break;
nRight = nRight - 1;
}
break;
case SortOrder.Descending:
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nLeft];
if (
Convert.ToDateTime(tmp[column]).CompareTo(Convert.ToDateTime(szPivot[column]
)) <= 0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
string[] tmp = (string[])szArray[nRight];
if
(Convert.ToDateTime(tmp[column]).CompareTo(Convert.ToDateTime(szPivot[column
])) > 0)
break;
nRight = nRight - 1;
}
break;
}
break;
#endregion
}
// Swap values if necessary
if (nLeft < nRight)
{
szSwap = (string[]) szArray[nLeft];
szArray[nLeft] = szArray[nRight];
szArray[nRight] = szSwap;
nLeft = nLeft + 1;
nRight = nRight - 1;
}
}
// Move pivot element
szSwap = (string[]) szArray[nLower];
szArray[nLower] = szArray[nRight];
szArray[nRight] = szSwap;
return nRight;
}
}
Grtz