Sorting Algorithm
Bert Freudenberg
bert at isg.cs.uni-magdeburg.de
Fri Nov 16 21:02:22 UTC 2001
On Fri, 16 Nov 2001, Christopher Roach wrote:
> I am just thinking here... will smalltalk do a comparison on each
> letter at a time? so lets say we have:
>
> aaaa
> compared to:
> aaab does smalltalk go through first a's and compare it, then move
> onto second a, compare that, until it gets to the fourth THEN it
> realizes that they are different and moves on?
Yes. It compares both character by character until it finds a difference.
> 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]]]]]]
>
> Does this in effect just get the first two characters of the field
> and do a comparison? yeah? the words "title" and "name" and all
> that in this method - does that make a difference? how does
> smalltalk regard that?
Sorry, I did not know just how new you are to Squeak.
> could it just be:
>
> order := [:a :b |
> a < b or: [
> a = b and: [a < b or: [
> a = b and: [a < b or: [
> a < b ]]]]]]
>
No, that would make no sense.
> Can you produce a record in smalltalk like in C++, so it could be
> something like:
>
> Struct
> {
> char[] name,
> char [] title,
> char [] ref,
> int number
> }
Yes, that is what I assumed you were doing. Both a and b in my code were
objects that had title, name, ref, and number members, just like your
struct. Explaining how to do this would take a while. You should work
through this tutorial:
http://www.squeak.org/tutorials/BankAccount.html
In C terms, the tutorial creates a struct that holds information on a bank
account:
struct {
int balance;
int history[];
}
After that, you should be able to define your own class.
-- Bert
More information about the Squeak-dev
mailing list
|