All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Rotating an array (Posted on 2004-04-19)
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.

 Submitted by e.g. Rating: 4.0000 (13 votes) Solution: (Hide) Call the array length L. First FLIP(1,L-N): H G F E D C B A I J K Then FLIP(L-N+1,N): H G F E D C B A K J I Finally, FLIP(1,N), and you are done.

 Subject Author Date Rotating an array the function FLIP() Prashant 2007-06-12 03:39:43 No Subject sundaram 2006-12-03 08:04:28 re: SOLUTION Amitava 2004-05-21 22:51:26 SOLUTION Amitava 2004-05-21 22:18:57 re(2): Here is a program that compares the algorithms Penny 2004-04-24 03:29:12 re(2): 10 step method logischer Verstand 2004-04-23 22:13:06 re: Here is a program that compares the algorithms Juggler 2004-04-20 19:19:11 a solution Saka 2004-04-20 13:06:54 Here is a program that compares the algorithms Penny 2004-04-20 13:04:39 re: 10 step method Federico Kereki 2004-04-20 12:38:19 re: A possible way Federico Kereki 2004-04-20 08:03:01 re: 10 step method Charlie 2004-04-19 23:24:52 A better way, from the beginning Oskar 2004-04-19 20:56:04 re: 3 Step Method SilverKnight 2004-04-19 20:30:22 Revised Algorithm Penny 2004-04-19 19:09:54 3 Step Method Juggler 2004-04-19 18:40:49 re(2): 10 step method logischer Verstand 2004-04-19 18:17:45 re: 10 step method SilverKnight 2004-04-19 18:02:43 re: Algorithm SilverKnight 2004-04-19 18:00:09 re(2): question for e.g. logischer Verstand 2004-04-19 17:58:58 10 step method logischer Verstand 2004-04-19 17:58:17 Algorithm Penny 2004-04-19 17:52:44 A possible way Oskar 2004-04-19 17:51:17 re: question for e.g. SilverKnight 2004-04-19 17:49:00 question for e.g. logischer Verstand 2004-04-19 17:39:36 one way Larry 2004-04-19 16:47:15

 Search: Search body:
Forums (0)