Sorting Algorithm

Stewart MacLean stingray at paradise.net.nz
Tue Nov 20 04:03:19 UTC 2001


Ahhh - I see it now. 

I think I prefer this way of coding sort blocks rather than using
ifTrue:ifFalse...It seems clearer.

Thanks,

Stewart

On
Tue, 20 Nov 2001, you wrote: > 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