How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Objeck programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Objeck 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 Objeck programming language
Source code in the objeck programming language
bundle Default {
class Stooge {
function : Main(args : String[]) ~ Nil {
nums := [3, 5, 1, 9, 7, 6, 8, 2, 4];
CombSort(nums);
each(i : nums) {
IO.Console->Print(nums[i])->Print(",");
};
IO.Console->PrintLine();
}
function : CombSort(input : Int[]) ~ Nil {
gap : Float := input->Size();
swaps := true;
while(gap > 1 | swaps) {
gap /= 1.247330950103979;
if(gap < 1) { gap := 1; };
i : Int := 0;
swaps := false;
while(i + gap < input->Size()) {
igap : Int := i + gap->As(Int);
if (input[i] > input[igap]) {
swap : Int := input[i];
input[i] := input[igap];
input[igap] := swap;
swaps := true;
};
i += 1;
};
};
}
}
}
You may also check:How to resolve the algorithm First-class functions step by step in the Oz programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Objective-C programming language
You may also check:How to resolve the algorithm Imaginary base numbers step by step in the Wren programming language
You may also check:How to resolve the algorithm Wireworld step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Function definition step by step in the Euphoria programming language