[plug] qsort
Cameron Patrick
cp at chem.com.au
Sun Jun 9 16:39:47 WST 2002
On Sun, Jun 09, 2002 at 04:39:08PM +0800, Richard wrote:
> Wouldn't it be easier just to write your own simple sort. This all seems
> a bit convoluted to me :)
Okay, here goes...
#define INFINITY 9999999
int is_sorted(int *list, int N)
{
int i;
int p = -INFINITY;
for (i=0; i<N; i++)
{
if (list[i] < p)
return 0;
}
return 1;
}
void bogosort(int *list, int N)
{
int a, b, x;
while (!is_sorted(list, N))
{
a = rand()%N;
b = rand()%N;
x = list[a];
list[a] = list[b]
list[b] = x;
}
}
BTW, this is untested. Pleeease don't use it. Ever. For anything.
CP.
More information about the plug
mailing list