TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Bob Lawrence
from: Roy McNeill
date: 1996-12-04 23:09:16
subject: Bloody C

Hi Bob



Just a comment -



 BL>   My problem is with qsort(). It gets totally stuffed up with the long

 BL> and variable-length lines. How the bloody hell can I make it sort

 BL> on just the first few characters in each line? When I try to rewrite

 BL> sort_function() it won't let me truncate the strings because it's

 BL> passing void pointers!



If your object is a sorting routine, and not an in-depth C lesson,

try writing your own. The first time I tried qsort(), I had much

the same trouble as you're having, so I found a book and wrote a

quicksort from scratch, building the comparison routine right in.

Worked well, and was probably a tad faster cos it avoided the

overhead of the function call.



I've read somewhere that quicksort is a bit overrated. On shorter

lists, the timesaving can be pretty well negligible, and on "almost

sorted" lists, some simpler routines can actually be faster. The

simpler ones are a bit easier to write, and don't make heavy

demands on the stack (repeated recursive function calls) on long

lists.



Cheers



--- PPoint 1.88


* Origin: Silicon Heaven (3:711/934.16)
SEEN-BY: 711/934 712/610
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.