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.
(In reply to
SOLUTION by Amitava)
for the examle at hand X=11 N=3
A-B-C-D-E-F-G-H-I-J-K
FLIP(1,11)
=> K-J-I-H-G-F-E-D-C-B-A
FLIP(4,11)
=> K-J-I-A-B-C-D-E-F-G-H
FLIP(1,3)
=>I-J-K-A-B-C-D-E-F-G-H
allright
|
Posted by Amitava
on 2004-05-21 22:51:26 |