[OCLUG-devel] Lexicographically Sorted
Christopher Smith
x at xman.org
Wed May 25 22:28:30 PDT 2005
Chris Berry wrote:
> That's interesting, and kind of scary, seems like every time I learn
> something new about computers it just reveals a whole new layer of
> ignorance on my part. Unfortuneately, the man pages you pointed to
> don't define lexicographic ordering. I'm not looking for a strcmp
> replacement, I'm doing an excercise as part of my C programming
> training. I don't want someone to do the work for me, I just need to
> know what lexicographical order is so I can figure out how to write
> the algorithm.
>
Apologies. I thought the man pages would make it clear. Alphabetical
ordering is a subset of lexical ordering. The difference is that lexical
ordering allows for sorting of non-alphabetical characters. All this
stuff is dealt with in detail in the locale support in POSIX (see the
link I provided). strcoll is not a strcmp replacement. They are similar
functions. strcmp compares strings based on ASCIIbetical order, strcoll
compares strings based on lexical ordering for the current POSIX locale.
POSIX is a standard seperate from the C language, so strcoll is
technically not part of C and perhaps using POSIX functions is
inappropriate for your situation, in which case you need to match
strcoll's functionality. Basically, the main thing you need is a lexical
alphabet to define what comes before what and what characters are
equivalent. If you can't use POSIX, you are going to need some other
source for determining that. Since you didn't mention having one, I
figured using POSIX was the way the instructor wanted you to go.
--Chris
More information about the OCLUG-devel
mailing list