Re: need an algo for string sorting
From: William (Reply_at_NewsGroup.Please)
Date: 08/19/04
- Next message: Thad Smith: "Re: need an algo for string sorting"
- Previous message: Markus Langlotz BTR Poegl Koma Tutor: "Re: hard disk faster than main memory?"
- In reply to: Raghavendra Mahuli: "need an algo for string sorting"
- Next in thread: Thad Smith: "Re: need an algo for string sorting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 19 Aug 2004 10:52:18 -0500
"Raghavendra Mahuli" <raghavendra.ma@in.bosch.com> wrote in message
news:cg1ds2$6mq$1@ns1.fe.internet.bosch.com...
> Hi,
> I have many strings. I have to sort them. But sorting is not according to
> ascii but according to a different format (which keeps varying) . So i can
> sort them based on sort-order. It is not much of a problem.
>
> But the complex part is "equivalent-values". it can be defined that "ai"
and
> "ae" are equivalent-values. Then, while sorting two strings, i have to
> consider that "ai" and "ae" are equal......only if they come at same
> position in both the strings....
It really isn't a sorting problem, it's a comparison issue. Write the
correct comparison routine and plug it into the sort routine of your
choice, e.g., quicksort.
At the basic level, you need to step through each string, extracting
"tokens" instead of characters. Your parsing routine has to know
that, for example, "ax" is two tokens, but 'ai' is one token. Parse out
a token from the same character index in each string. If the lengths of
the tokens don't match, you know the strings are unequal. If the
lengths match, then you need to run through some logic that can
determine if the tokens are equivalent. This can be done with
comparisons, table lookups, hashing, regular expressions, or a
combination. The choices depend a lot on the language. Some will
offer "tricks" you can apply such as this piece of bourne shell script:
case "${Token1}$Token2" in
aiae|aeai|aiai|aeae) echo "equal" ;;
*) echo "not equal" ;;
esac
In Perl you could create a hash where each of those combinations
returns true when applied as a key. -Wm
- Next message: Thad Smith: "Re: need an algo for string sorting"
- Previous message: Markus Langlotz BTR Poegl Koma Tutor: "Re: hard disk faster than main memory?"
- In reply to: Raghavendra Mahuli: "need an algo for string sorting"
- Next in thread: Thad Smith: "Re: need an algo for string sorting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|