Anonymous user
Sorting algorithms/Comb sort: Difference between revisions
m
→Less Clever Version
(Added solution for Action!) |
|||
Line 1,439:
This version is an academic demonstration that aligns with the algorithm. As is, it is limited to use one static array and sorts in ascending order only.
<lang forth>\ combsort for the Forth Newbie (GForth)
HEX
\ gratuitous variables
VARIABLE SORTED
DECIMAL
Line 1,449 ⟶ 1,448:
\ allocate a small array of cells
CREATE Q SIZE 2+ CELLS ALLOT
\ operator to index into the array
Line 1,455 ⟶ 1,454:
\ fill array and see array
: INITDATA ( -- ) SIZE 0 DO
▲: SEEDATA ( -- ) CR SIZE 0 DO I ]Q @ U. LOOP ;
\
\
:
: XCHG ( adr1 adr2 n1 n2-- ) OVER @ OVER @ SWAP ROT ! SWAP ! ;▼
▲: XCHG ( adr1 adr2 n1 n2-- ) SWAP ROT ! SWAP ! ;
: COMBSORT ( n -- )
DUP
BEGIN
GAP
SORTED ON
DO
I GAP
IF
SORTED OFF \ flag we are not sorted
THEN
LOOP
SORTED @ GAP
UNTIL
DROP
;
=={{header|Fortran}}==
|