home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!ucbvax!amex-trs.com!gonzalod
- From: gonzalod@amex-trs.com (Gonzalo Diethelm)
- Newsgroups: comp.misc
- Subject: Generic sorting functions
- Message-ID: <9208212151.AA38407@cs90code.csv-tgsc.amex-trs.com>
- Date: 21 Aug 92 21:51:31 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Lines: 42
-
-
-
- Distribution: world
-
- Hello everyone,
-
- A very generic question. Given a set S of n strings (the `|' characters
- are used as delimiters):
-
- s1 |dunno|
- s2 |I'd rather have a bottle in front of me than a frontal lobotomy|
- s3 |eschew clever rules|
- ... ...
- sn |bzzzzt!|
-
- and an ordering sequence O:
-
- {s4, s1, s6, s2, sn, s3, ... s7}
-
- is there any way to determine a fixed, hopefully cheap function
-
- f(): SxS -> integers
-
- with the property that
-
- if si comes before sj in O, f(si, sj) < 0
- if si comes after sj in O, f(si, sj) > 0
-
- that is, could be used to sort the strings in the given sequence?
- For example, if the desired sequence happens to be the alphabetical
- descending ordering of the strings, f() could just be
-
- f = -1 * strcmp(si, sj);
-
- My intuiton tells me this is possible, but I don't really know how
- to approach the problem. Any help is welcome. Please send answers
- and flames via e-mail. Thanks in advance and kindest regards.
-
- gonzalod@amexphx.amex-trs.com
- Gonzalo A. Diethelm (602)375-8410 home
- 16220 N 7th St Ap 1314 (602)492-3536 office
- Phoenix, AZ 85022 (602)492-4248 FAX
-