[plug] qsort

Richard wpickett at iprimus.com.au
Sun Jun 9 16:56:28 WST 2002


On Sun, 2002-06-09 at 16:39, Cameron Patrick wrote:
> 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.
> 
I think bogosort() has a nice ring to it, we'll surely be seeing more of that
one in the future :)



More information about the plug mailing list