Hi Bert, Hi DeBruicker a slight tweak to Bert's method
a height = b height ifFalse: [ a height < b height ] ifTrue: [ a width = b width ifFalse: [ a width < b width ] ifTrue: [ a depth <= b depth ] ] .
Basically if primary sorts values are unequal sort by primary values else sort by secondry values etc. This basicly recusive procedure will work for any number of sort levels.
Yours in curiosity and service, --Jerome Peace
--- On Mon, 4/12/10, Bert Freudenberg bert@freudenbergs.de wrote:
From: Bert Freudenberg bert@freudenbergs.de Subject: Re: [Newbies] How to sort a SortedCollection like you can sort a table in Excel? To: "A friendly place to get answers to even the most basic questions about Squeak." beginners@lists.squeakfoundation.org Date: Monday, April 12, 2010, 10:36 AM On 12.04.2010, at 16:13, Paul DeBruicker wrote:
Hi -
If I had a SortedCollection of rectangular solid
objects (that just have
the ivars height, width, depth), how could I sort it
by height, then
width, then depth?
So three object:
A) h: 10, w: 5, d: 3 B) h: 60, w: 2, d: 14 C) h: 10, w: 3, d: 27
And then after sorting they'd be in this order:
B) h: 60, w: 2, d: 14 A) h: 10, w: 5, d: 3 C) h: 10, w: 3, d: 27
First sorted by height, then by width, then by
depth.
Is there a way to do that using just a
#sortBlock:
Sure. Basically your sort block would look like
a height > b height or: [ a height = b height and: [ a width > b width or: [ a width = b width and: [ a depth > b depth]]]]
- Bert -
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners