How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Liberty BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Liberty BASIC programming language

Table of Contents

Problem Statement

Implement a   comb sort.

The Comb Sort is a variant of the Bubble Sort. Like the Shell sort, the Comb Sort increases the gap used in comparisons and exchanges. Dividing the gap by

( 1 −

e

− φ

)

− 1

≈ 1.247330950103979

{\displaystyle (1-e^{-\varphi })^{-1}\approx 1.247330950103979}

works best, but   1.3   may be more practical.

Some implementations use the insertion sort once the gap is less than a certain amount.

Variants:

Pseudocode:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Liberty BASIC programming language

Source code in the liberty programming language

'randomize 0.5
itemCount = 20
    dim item(itemCount)
    for i = 1 to itemCount
        item(i) = int(rnd(1) * 100)
    next i
    print "Before Sort"
    for i = 1 to itemCount
        print item(i)
    next i
    print: print
't0=time$("ms")

    gap=itemCount
    while gap>1 or swaps <> 0
        gap=int(gap/1.25)
        'if gap = 10 or gap = 9 then gap = 11    'uncomment to get Combsort11
        if gap <1 then gap = 1
        i = 1
        swaps = 0
        for i = 1 to itemCount-gap
            if item(i) > item(i + gap) then
                temp = item(i)
                item(i) = item(i + gap)
                item(i + gap) = temp
                swaps = 1
            end if
        next
    wend

    print "After Sort"
't1=time$("ms")
'print t1-t0

    for i = 1 to itemCount
        print item(i)
    next i
end

  

You may also check:How to resolve the algorithm Literals/Integer step by step in the Oforth programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Terraform programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Delphi programming language
You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the Wren programming language
You may also check:How to resolve the algorithm File modification time step by step in the PicoLisp programming language