Shift list elements to left by 3: Difference between revisions

Add CLU
(Added solution for Action!)
(Add CLU)
Line 671:
After: 4 5 6 7 8 9 1 2 3
</pre>
 
=={{header|CLU}}==
<lang clu>% Shift an array left by a certain amount
shift_left = proc [T: type] (a: array[T], n: int)
at = array[T]
% shifting an empty array is a no-op
if at$empty(a) then return end
% otherwise we take elements from the bottom
% and put them at the top
low: int := at$low(a)
for i: int in int$from_to(1, n) do
at$addh(a, at$reml(a))
end
at$set_low(a, low)
end shift_left
 
show = proc (s: stream, a: array[int])
for i: int in array[int]$elements(a) do
stream$puts(s, int$unparse(i) || " ")
end
stream$putc(s,'\n')
end show
 
start_up = proc ()
po: stream := stream$primary_output()
arr: array[int] := array[int]$[1,2,3,4,5,6,7,8,9]
stream$puts(po, "Before: ") show(po, arr)
shift_left[int](arr, 3)
stream$puts(po, " After: ") show(po, arr)
end start_up </lang>
{{out}}
<pre>Before: 1 2 3 4 5 6 7 8 9
After: 4 5 6 7 8 9 1 2 3</pre>
 
=={{header|Common Lisp}}==
2,112

edits