[thelist] 1.1.2 Sorting
MarsHall
evolt at marsorange.com
Thu Dec 5 16:35:01 CST 2002
On Thursday, Dec 5, 2002, at 14:52 US/Central, rudy wrote:
> i'm sure there must be a better approach
The function to make each number sortable could flow like this:
1. decide the number of digits each number can contain; call this D
if 99.99.99 is the maximum, then D = 2
if 999.999.999 is the maximum, then D = 3
2. split/explode the input string on the periods
3. for each split element (moving left to right; most significant first)
a. determine the string length of the current element; call this L
b. D - L = N,
c. append N "0"'s to the left the current element
d. append the current element to a [new] array of the zero-padded
elements
4. unsplit/implode the array of zero-padded elements with a period
You could use these values to build an index and sort on that index.
Mars :)
More information about the thelist
mailing list