quicksort trauma
i remmeber back then i was revriting quicksort form
wikipedia or some other poage and tested multiple
versions of it
at some moment i changed something (as i remember i
repleced do while on while this way it seemd to me
it should work but i made some mistake and some
versions were wrong and i not noticed that
- later i afair repaired that but in my
older codes i got verions which im not sure is for
sure right or not
for example this one
void QuicksortInts7(int* table, int lo, int hi)
{
int i=lo; int j=hi;
while (i<hi)
{
int pivot =table[(lo+hi)/2];
while (i<=j) // Partition
{
while (table[i]<pivot) i++;
while (table[j]>pivot) j--;
if (i<=j)
{
int t=table[i];table[i]=table[j];table[j]=t;
i++; j--;
}
}
if (lo < j){ QuicksortInts7(table, lo, j);} //recursion
lo=i; j=hi;
}
}
how can i be sure this is right?? do generation of random array
and comoper results with say qsort from c-lib is enough?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 299 |
Nodes: | 16 (2 / 14) |
Uptime: | 51:04:01 |
Calls: | 6,689 |
Calls today: | 7 |
Files: | 12,225 |
Messages: | 5,344,600 |
Posted today: | 1 |