Sorting algorithms/Comb sort: Difference between revisions
Content added Content deleted
Line 215: | Line 215: | ||
{CombSort Arr} |
{CombSort Arr} |
||
{Show {Array.toRecord unit Arr}}</lang> |
{Show {Array.toRecord unit Arr}}</lang> |
||
=={{header|PL/I}}== |
|||
<lang PL/I> |
|||
/* From the pseudocode. */ |
|||
comb_sort: procedure (A); |
|||
declare A(*) fixed; |
|||
declare t fixed; |
|||
declare (i, gap) fixed binary (31); |
|||
declare swaps bit (1) aligned; |
|||
gap = hbound(A,1); /* initialize the gap size. */ |
|||
do until (gap <= 1 & swaps); |
|||
/* update the gap value for a next comb. */ |
|||
gap = gap / 1.25; |
|||
swaps = '1'b; |
|||
/* a single "comb" over the array. */ |
|||
do i = 0 by 1 until (i + gap >= hbound(A,1)); |
|||
if A(i) > A(i+gap) then |
|||
do; |
|||
t = A(i); A(i) = A(i+gap); A(i+gap) = t; |
|||
swaps := '0'b; /* Flag a swap has occurred, so */ |
|||
/* the list is not guaranteed sorted. */ |
|||
end; |
|||
end; |
|||
end; |
|||
end comb_sort; |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
Implementation of CombSort11. |
Implementation of CombSort11. |