"Patrick de Ridder" <wa********@all.here> wrote in message
news:4a***************************@freeler.nl...
"VM" <vo******@yahoo.com> wrote in message
news:O8**************@TK2MSFTNGP11.phx.gbl... How can I sort a datatable by a certain col after the table is filled?
The way you can do that is sticking each column into an array.
Then use a sort algorithm and sort all the arrays together
using the order defining column in the swap function. If
you need a sort class let me know.
You have to do the sorting before you bind the data to the table.
If there are three columns:
Take a,b,c bigger than necessary and later knock off the zeros
because of the n/2. I used static variables for a,b,c.
using System;
namespace xyz
{
public class Sort
{
private int [ ] a = new int[50];
private int [ ] b = new int[50];
private int [ ] c = new int[50];
private int lo;
private int hi;
public Sort(int [ ] a,int [ ] b,int [ ] c,int lo, int hi)
{
this.a = a;
this.b = b;
this.c = c;
this.hi = hi;
this.lo = lo;
quicksort(a,b,c,lo,hi);
}
public void quicksort(int [ ] a, int [ ] b, int [ ] c, int lo, int hi)
{
int i = lo;
int j = hi;
int h1 = 0;
int h2 = 0;
int h3 = 0;
int x = a[(lo+hi)/2];
do
{
while(a[i]<x) i++;
while(a[j]>x) j--;
if(i<=j)
{
h1=a[i];a[i]=a[j];a[j]=h1;
h2=b[i];b[i]=b[j];b[j]=h2;
h3=c[i];c[i]=c[j];c[j]=h3;
i++;
j--;
}
}while(i<=j);
if (lo<j) quicksort(a,b,c,lo,j);
if (i<hi)quicksort(a,b,c,i,hi);
}
}
}