I have an array such as
A-B-C-D-E-F-G-H-I-J-K
I want to rotate it N places to the right; for example, if N=3, the array should end
I-J-K-A-B-C-D-E-F-G-H
Assume that the only available operation is a FLIP method that can invert any portion of the array. For example, applied to the original array FLIP(3,6) would produce A-B-F-E-D-C-G-H-I-J-K.
I suppose you could, assuming the array was X long (in this case 11) at all times, use 3 FLIPs
FLIP(1,X) -> K-J-I-H-G-F-E-D-C-B-A
FLIP (1,N) -> I-J-K-H-G-F-E-D-C-B-A
FLIP (N+1,X) -> I-J-K-A-B-C-D-E-F-G-H
|
Posted by Saka
on 2004-04-20 13:06:54 |