🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #1037

Re: Quicksort/quicksort()

#1037
From: Amit J Patel
Date: Mon, 09 Nov 1992 14:02
46 lines
1688 bytes
In article <32545@mavenry.UUCP>, the.maven@mavenry.UUCP writes:
|>  
|>  Regarding sort algorithms, you may or may not want to use the ansi 
|> quicksort() function. ANSI standards mandate the function's presence, but do 
|> very little to define it's implementation. I know of a couple compilers 
|> which implement a bubble sort as quicksort()... If you don't have the RTL 
|> source for your compiler (so you could check) you might want to find another 
|> Quick Sort routine and test that for speed against your compiler's... 

Even if it really is a quick sort, it's not too efficient, because it
has to make a function call for every comparison.  If you're sorting
ints, compare:


	int a,b;


						int foo(int a,b) 
						{
							return a<b;
						}

	if(a<b)			vs.		if( compare(a,b) )



and


	temp = a;		vs.		memcpy(&temp,&a,sz);
	a = b;					memcpy(&a,&b,sz);
	b = temp;				memcpy(&b,&temp,sz);


Writing your own qsort, radix sort, merge sort, or heap sort would be
better than using their library because the compiler can use inline
the comparisons and swaps.




		Amit


P.S.  C++ templates seem to be the way to write qsort() once and not
	lose efficiency.
Technical Details
Message-ID: <BxGCC5.CHo@rice.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!uw-beaver!rice!owlnet.rice.edu!amitp
References: <32545@mavenry.UUCP>

Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!uw-beaver!rice!owlnet.rice.edu!amitp
From: amitp@owlnet.rice.edu (Amit J Patel)
Subject: Re: Quicksort/quicksort()
Message-ID: <BxGCC5.CHo@rice.edu>
Sender: news@rice.edu (News)
Reply-To: amitp@owlnet.rice.edu
Organization: Rice University
References:  <32545@mavenry.UUCP>
Date: Mon, 9 Nov 1992 14:02:28 GMT
Lines: 46