Liberty BASIC Community Forum
« Comb Sort »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 11:03am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Comb Sort  (Read 197 times)
Jack Kelly
New Member
Image


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 17
xx Comb Sort
« Thread started on: Oct 24th, 2016, 08:24am »

Continuation of Allincon's previous post on Bubble Sorts:

This is my favorite. It's like a bubble sort on amphetamines! It makes a BIG difference on lists of over a thousand items.

Code:
sub CombSort chosenCtr
    Size=chosenCtr
    Gap=Size
    Shrink=1.3
    do until Gap=1 and Sorted
        Gap=int(Gap/Shrink)
        if Gap<1 then Gap=1
        j=1
        Sorted=1
        do while j+Gap<=chosenCtr
            if lower$(mid$(classChosen$(j),17,4)) >_
                    lower$(mid$(classChosen$(j+Gap),17,4)) then
		      temp$ = classChosen$(j)  
		      classChosen$(j)=classChosen$(j+Gap)
		      classChosen$(j+Gap)=temp$
              Sorted=0
            end if
            j=j+1
        loop
    loop
end sub 


It includes a 'Sorted' flag which allow it to terminate as soon as it's done. The 'lower$()' function in the compare makes it case insensitive, which is nice sometimes.
« Last Edit: Oct 24th, 2016, 08:26am by Jack Kelly » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Comb Sort
« Reply #1 on: Oct 24th, 2016, 11:30am »

I feel a challenge coming on 😀

I once posted to a challenge on sorting, I was pleased with the speed I had achieved, Wellopez blew me out the water with a sort near one hundred times faster than mine.

So who is saying fastest and putting their routine on the table?.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls