Sorting algorithms/Gnome sort: Difference between revisions
Content deleted Content added
→{{header|XPL0}}: Added zkl |
First implementation in PL/I |
||
Line 1,872: | Line 1,872: | ||
(setq I (prior I Lst)) ) ) ) ) |
(setq I (prior I Lst)) ) ) ) ) |
||
Lst )</lang> |
Lst )</lang> |
||
=={{header|PL/I}}== |
|||
<lang PL/I>SORT: PROCEDURE OPTIONS (MAIN); |
|||
DECLARE A(0:9) FIXED STATIC INITIAL (5, 2, 7, 1, 9, 8, 6, 3, 4, 0); |
|||
CALL GNOME_SORT (A); |
|||
put skip edit (A) (f(7)); |
|||
GNOME_SORT: PROCEDURE (A) OPTIONS (REORDER); /* 9 September 2015 */ |
|||
declare A(*) fixed; |
|||
declare t fixed; |
|||
declare (i, j) fixed; |
|||
i = 1; j = 2; |
|||
do while (i <= hbound(A)); |
|||
if a(i-1) <= a(i) then |
|||
do; |
|||
i = j; j = j + 1; |
|||
end; |
|||
else |
|||
do; |
|||
t = a(i-1); a(i-1) = a(i); a(i) = t; |
|||
i = i - 1; |
|||
if i = 0 then do; i = j; j = j + 1; end; |
|||
end; |
|||
end; |
|||
END GNOME_SORT; |
|||
END SORT;</lang> |
|||
Results: |
|||
<pre> |
|||
0 1 2 3 4 5 6 7 8 9 |
|||
</pre> |
|||
=={{header|PowerBASIC}}== |
=={{header|PowerBASIC}}== |