home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!quads!pynq
- From: pynq@quads.uchicago.edu (George Jetson)
- Subject: Sorting (continued)
- Message-ID: <1992Aug15.135836.23357@midway.uchicago.edu>
- Summary: Looking for best sort algorithm
- Sender: news@uchinews.uchicago.edu (News System)
- Reply-To: pynq@midway.uchicago.edu
- Organization: D. J. Dougherty & Associates
- Date: Sat, 15 Aug 1992 13:58:36 GMT
- Lines: 47
-
- (I know this doesn't really belong in comp.lang.c, being as it is an
- algorithm question. Please advise as to better newsgroup(s))
-
- I am trying to design an in-memory sort (no, this is not a class project)
- (I'm too old for that crap..., but seriously folks...) and have narrowed
- it down to 3 possible algorithms. Note: It is a requirement that the
- design not place any limits on the input (i.e., record length or number
- of records) Which do you think would be the best/most efficient?
-
- 1) Build up a data structure along the lines of:
-
- struct thing {char *key,*text;}
-
- where the things are malloc'd in blocks and you periodically
- realloc them, so as to keep a contiguous block of memory.
- (I am assuming that realloc does recopy the data if it needs
- to move the block - this re-copying could be costly)
-
- After reading all the input, call the qsort() intrinsic.
-
- 2) Build up a linked list, along the lines of:
-
- struct thing {char *key,*text; struct thing *next;}
-
- Now, you don't have to do any reallocs, but at the end, you
- have to traverse the list, and build an array of pointers to
- the things and qsort that. (You keep a count on the first
- pass so that you known how big to calloc the array of
- pointers)
-
- 3) Build a binary tree in the first pass, then simply print the
- tree in traversal order.
-
- Thanks for any and all help. These are essentially the choices, but
- feel free to point out any errors in my analysis.
-
-
- (I need to re-read Knuth...)
-
- ************************************************************************
- Please don't drink the battery acid, it tastes bad and will hurt you.
- Also, don't bite the tyres, especially when the bike is moving.
- (Our lawyers made us put this in this manual.)
-
- - pynq@quads.uchicago.edu, who is still costing the net
- hundreds, if not thousands, of dollars, every time he posts -
- ************************************************************************
-