Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Array Sort Challenge...
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00218459
Message ID:
00218982
Views:
18
BOb,

Mike McLain was right on the money about adding an additional column to do this. Otherwise, it simply isn't worth the overhead required. Let me explain why.

If this is done within the sort, some function to return the necessary combined values is going to be called twice and evaluated. In your sample, using a simple bubble sort would lead to a minimum of 5 factorial times 2 calls (240 if my math is right) on your 6 element array. Even a recursive Quick Sort would end up having to call the same functions at least twice as many times as you would if you created the additional column before hand, and this is the absolute minimum. So simply put, creating an additional column, filling it with with the necessary values, and calling ASORT() is always going to be more efficient, than writing a sort routine yourself. Note that I haven't even addressed the issue of swapping the array elements, which will add additional overhead.

If you want one more reason to go with ASORT() consider that you're calling a native function against your tokenized pcode.

Regards,
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform