Hi,
Does anyone know of an efficient way of reversing the order of items in an array? Potentially hundreds of items, so it would be best not to iterate and copy them one by one to a new array…
all best
Øyvind
Hi,
Does anyone know of an efficient way of reversing the order of items in an
array?
...
Possibly a very stupid question: is it unfeasible of reverting the
indexing with the help of lenarray? An efficient way of doing that might
be with linlin remapping indices running from 0.
If you want to reverse an array in place then you loop on half the length and swap a[i] with a[n-1]. Of course fiddling the index as Jeanette suggested is more efficient but not always possible.
A reversearray opcode would be nice, and also nice if it could be done as an extension of an existing opcode. Maybe slicearray could do it? (if istart is larger than iend, the output slice would be reversed)
iarr[] fillarray 1,2,3,4
ireverse slicearray iarr,3,0
(this does not work now btw, but could be practical)
Øyvind