Sorting Algorithm
Richard A. O'Keefe
ok at atlas.otago.ac.nz
Tue Nov 20 03:37:14 UTC 2001
Stewart MacLean <stingray at paradise.net.nz> wrote:
It's late, can't see it?
>
> The code that Bert gave:
>
> order := [:a :b |
> a title < b title or: [
> a title = b title and: [a name < b name or: [
> a name = b name and: [a ref < b ref or: [
> a number < b number]]]]]]
>
> [There is an obvious error in this, which I leave as an exercise for
> the reader.]
>
title is tested twice,
name is tested twice,
ref SHOULD be tested twice, but is only tested once.
Ordering blocks should generally act like <=, so
the code should be
order := [:a :b | "a <= b"
a title < b title or:
[a title = b title and:
[a name < b name or:
[a name = b name and:
[a ref < b ref or:
[a ref = b ref and: "this was missing"
[a number <= b number]]]]]]]. "this was <"
More information about the Squeak-dev
mailing list
|