ADDRESSOF and SORTARRAY questions

Previous topic - Next topic

CatouSan

How could arrays of types and extended types use the same routine as arrays of ints and floats? I have been pulling out my hair trying to figure that out..

MrTAToad

#16
No, they would use a separate routine.

Integers/floats would use one routine
Types use another
Strings would use another one

It would be possible only three sort routines would be needed.

CatouSan

I see. So when you say types use one routine, are you referring to all types? Ex. I can use one function to sort an array of dogs, and later an array of cats?

MrTAToad

Yes, I dont see why not unless the arrays have different type structures...

Moru

#19
You need one routine for each type structure. TYPE Cats need one routine, TYPE Dogs need another routine. Ofcourse, the comparison would have been easier to not misunderstand if you had used TYPE Animals and TYPE Cars. Or something :-)

MrTAToad

Or you could have a type of TAnimals and then an array for cats and dogs...

CatouSan

You guys gave me some ideas I will apply to create a solution, it will be a pain, but it will also be elegant.

Thanks again  :)

Kitty Hello

SORTARRAY uses the < (less than) operator of an array's element. So, if you have integers, floats or strings, they are sorted automatically.
The TYPE arrays have a built-in less-than operator that works by the order you write the type members top to bottom.
If you want a different sorting order (e.g. sort numbers by the length when you print them), you have to provide a sorting function.

CatouSan

Quote from: Ocean on 2011-Nov-28
Quote from: CatouSan on 2011-Nov-28
You guys gave me some ideas I will apply to create a solution, it will be a pain, but it will also be elegant.

Thanks again  :)

how can something elegant e a pain?
Elegant in how it works, a pain to write.   :P