|
On Thu, 15 Feb 2007 12:43:40 +0530 ewart.desouza@xxxxxxxxxxx wrote:
I would like to sort the following array on the first 7 fields i.e. from WWBCD through WATNNB. Is it possible using SORTA ??? According to the manual you can sort only one field at a time.
It'd be nice to do a radix sort. A radix sort is a kind of super sort that makes multiple passes. You'd make seven passes. The first sort would be on the least significant field. The second would be on the next most significant field, and so on. The last sort would be on the most significant field. You can kind of see it work in a miniature example. The leftmost column is the input. I sort them by the ones column, then by the tens column, then by the hundreds column. 329 651 329 329 757 -> 757 -> 651 -> 651 651 329 757 757 The one trick is that the sort you use to do a radix sort must be "stable", meaning that if the compared fields are equal, they should come out in the same order that they went in. I think I see in the SORTA documentation that it isn't stable. That's sad, because it would have been really nice. Here are some stable sorts you could implement, if you choose to do it the radix way: http://en.wikipedia.org/wiki/Category:Stable_sorts I guess you could also use qsort to do it. It would just have kind of a nasty comparison function. The comparison function would start by comparing the most significant fields. If they were unequal, you could return your decision. If they were equal, you'd have to check the next most significant field, and so on.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.