[futurebasic] Re: [FB] Sorting differences - FB4 vs FB2

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2008 : Group Archive : Group : All Groups

From: Brian Stevens <bstevens33@...>
Date: Fri, 31 Oct 2008 20:24:30 -0700
On Oct 31, 2008, at 6:01 PM, Robert Purves wrote:

>
> Pierre Zippi wrote:
>
>> Any ideas why this sort never exits the DO : UNTIL gap=0 loop?
>>
>> CLEAR LOCAL
>> DIM 50 sortedStr$(_maxRowCol)     'only use 50 char str
>> LOCAL FN AlphaSort
>> LONG IF multiSort%=0
>> FOR col=0 TO gTotalCol-1       'Re-set to original index%(x) order
>> index%(col)=col
>> NEXT col
>> END IF
>> FOR x=0 TO gTotalCol-1         'assign same values to new array
>> sortedStr$(x)=COLUMNLABELS$(x)
>> NEXT x
>> size=gTotalCol-2                    'was size=_numberOfItems-1, but
>> didn't sort last entry
>> gap=size
>> DO
>> gap=INT(gap.3)                    'fp divide
>> FOR count= 0 TO size-gap     'sort
>> theItem=count+gap                 'get the item to sort out
>> LONG IF sortedStr$(count+1)>sortedStr$(theItem+1)        ' see if it
>> is larger (add 1 cor col label)
>> SWAP sortedStr$(count+1),sortedStr$(theItem+1)             'swap if
>> true(add 1 cor col label)
>> SWAP index%(count),index%(theItem)                              'swap
>> index (no 1 for reg index)
>> END IF
>> NEXT count
>> UNTIL gap=0          'loop until
>> END FN
>
>
> gap = int( gap / 1.3 ) 'fp divide

Which is standard for a coombsort. Depending on data they are  
necessarily the fastest.

btw: there are other options to a standalone sort like the  
CFIndex.incl. It includes a fn CFIndexSort. This is available in both  
FB4 and FB5. Let me know if you need an example how to use it.

Brian S