How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the BBC BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the BBC BASIC programming language
Table of Contents
Problem Statement
The cocktail shaker sort is an improvement on the Bubble Sort. The improvement is basically that values "bubble" both directions through the array, because on each iteration the cocktail shaker sort bubble sorts once forwards and once backwards. Pseudocode for the algorithm (from wikipedia):
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the BBC BASIC programming language
Source code in the bbc programming language
DEF PROC_ShakerSort(Size%)
Start%=2
End%=Size%
Direction%=1
LastChange%=1
REPEAT
FOR J% = Start% TO End% STEP Direction%
IF data%(J%-1) > data%(J%) THEN
SWAP data%(J%-1),data%(J%)
LastChange% = J%
ENDIF
NEXT J%
End% = Start%
Start% = LastChange% - Direction%
Direction% = Direction% * -1
UNTIL ( ( End% * Direction% ) < ( Start% * Direction% ) )
ENDPROC
You may also check:How to resolve the algorithm Sleep step by step in the Aime programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the Swift programming language
You may also check:How to resolve the algorithm Ormiston triples step by step in the Raku programming language
You may also check:How to resolve the algorithm Binary search step by step in the Action! programming language
You may also check:How to resolve the algorithm Inverted syntax step by step in the C programming language