Sattolo cycle: Difference between revisions

(Added Algol 68)
Line 74:
Arrays in Algol 68 need not have a lower bound of 0, other than that, this implements the pseudo code.
<lang algol68>BEGIN
# reorders the elements of a using the SattaloSattolo cycle #
# this operates on integer arrays, additional SATTALOSATTOLO operators #
# could be defined for other types #
# a is returned so we can write e.g. SATTALOSATTOLO SATTALOSATTOLO a to cycle #
# the elements twice #
OP SATTALOSATTOLO = ( REF[]INT a )REF[]INT:
BEGIN
REF[]INT aa := a[ @ 0 ];
Line 89:
OD;
a
END # SATTALOSATTOLO # ;
[ 1 : 10 ]INT a := []INT( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )[ @ 1 ];
TO 5 DO
SATTALOSATTOLO a;
FOR i FROM LWB a TO UPB a DO print( ( " ", whole( a[ i ], -3 ) ) ) OD;
print( ( newline ) )
OD
END</lang>
</lang>
{{out}}
<pre>
3,044

edits