Sorting algorithms/Cocktail sort with shifting bounds: Difference between revisions
Content added Content deleted
(Sorting algorithms/Cocktail sort with shifting bounds en FreeBASIC) |
(Added solution for Action!) |
||
Line 402: | Line 402: | ||
.include "../includeARM64.inc" |
.include "../includeARM64.inc" |
||
</lang> |
</lang> |
||
=={{header|Action!}}== |
|||
<lang Action!>PROC PrintArray(INT ARRAY a INT size) |
|||
INT i |
|||
Put('[) |
|||
FOR i=0 TO size-1 |
|||
DO |
|||
IF i>0 THEN Put(' ) FI |
|||
PrintI(a(i)) |
|||
OD |
|||
Put(']) PutE() |
|||
RETURN |
|||
PROC CoctailShakerSort(INT ARRAY a INT size) |
|||
INT begIdx,endIdx,newBegIdx,newEndIdx,i,tmp |
|||
begIdx=0 endIdx=size-2 |
|||
WHILE begIdx<=endIdx |
|||
DO |
|||
newBegIdx=endIdx |
|||
newEndIdx=begIdx |
|||
i=begIdx |
|||
WHILE i<=endIdx |
|||
DO |
|||
IF a(i)>a(i+1) THEN |
|||
tmp=a(i) a(i)=a(i+1) a(i+1)=tmp |
|||
newEndIdx=i |
|||
FI |
|||
i==+1 |
|||
OD |
|||
endIdx=newEndIdx-1 |
|||
i=endIdx |
|||
WHILE i>=begIdx |
|||
DO |
|||
IF a(i)>a(i+1) THEN |
|||
tmp=a(i) a(i)=a(i+1) a(i+1)=tmp |
|||
newBegIdx=i |
|||
FI |
|||
i==-1 |
|||
OD |
|||
begIdx=newBegIdx+1 |
|||
OD |
|||
RETURN |
|||
PROC Test(INT ARRAY a INT size) |
|||
PrintE("Array before sort:") |
|||
PrintArray(a,size) |
|||
CoctailShakerSort(a,size) |
|||
PrintE("Array after sort:") |
|||
PrintArray(a,size) |
|||
PutE() |
|||
RETURN |
|||
PROC Main() |
|||
INT ARRAY |
|||
a(10)=[1 4 65535 0 3 7 4 8 20 65530], |
|||
b(21)=[10 9 8 7 6 5 4 3 2 1 0 |
|||
65535 65534 65533 65532 65531 |
|||
65530 65529 65528 65527 65526], |
|||
c(8)=[101 102 103 104 105 106 107 108], |
|||
d(12)=[1 65535 1 65535 1 65535 1 |
|||
65535 1 65535 1 65535] |
|||
Test(a,10) |
|||
Test(b,21) |
|||
Test(c,8) |
|||
Test(d,12) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Cocktail_sort_with_shifting_bounds.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
Array before sort: |
|||
[1 4 -1 0 3 7 4 8 20 -6] |
|||
Array after sort: |
|||
[-6 -1 0 1 3 4 4 7 8 20] |
|||
Array before sort: |
|||
[10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10] |
|||
Array after sort: |
|||
[-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10] |
|||
Array before sort: |
|||
[101 102 103 104 105 106 107 108] |
|||
Array after sort: |
|||
[101 102 103 104 105 106 107 108] |
|||
Array before sort: |
|||
[1 -1 1 -1 1 -1 1 -1 1 -1 1 -1] |
|||
Array after sort: |
|||
[-1 -1 -1 -1 -1 -1 1 1 1 1 1 1] |
|||
</pre> |
|||
=={{header|ALGOL 60}}== |
=={{header|ALGOL 60}}== |
||
{{works with|A60}} |
{{works with|A60}} |
||
Line 466: | Line 559: | ||
3 6 14 16 19 23 28 33 33 47 61 62 64 67 73 77 78 81 83 92 |
3 6 14 16 19 23 28 33 33 47 61 62 64 67 73 77 78 81 83 92 |
||
</pre> |
</pre> |
||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |