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

Home > Algorithms
Rotating an array (Posted on 2004-04-19) Difficulty: 2 of 5
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.

Comments: ( You must be logged in to post comments.)
  Subject Author Date
SolutionRotating an array the function FLIP()Prashant2007-06-12 03:39:43
No Subjectsundaram2006-12-03 08:04:28
re: SOLUTIONAmitava2004-05-21 22:51:26
SOLUTIONAmitava2004-05-21 22:18:57
re(2): Here is a program that compares the algorithmsPenny2004-04-24 03:29:12
Solutionre(2): 10 step methodlogischer Verstand2004-04-23 22:13:06
re: Here is a program that compares the algorithmsJuggler2004-04-20 19:19:11
Solutiona solutionSaka2004-04-20 13:06:54
Here is a program that compares the algorithmsPenny2004-04-20 13:04:39
re: 10 step methodFederico Kereki2004-04-20 12:38:19
Some Thoughtsre: A possible wayFederico Kereki2004-04-20 08:03:01
re: 10 step methodCharlie2004-04-19 23:24:52
SolutionA better way, from the beginningOskar2004-04-19 20:56:04
re: 3 Step MethodSilverKnight2004-04-19 20:30:22
SolutionRevised AlgorithmPenny2004-04-19 19:09:54
Solution3 Step MethodJuggler2004-04-19 18:40:49
re(2): 10 step methodlogischer Verstand2004-04-19 18:17:45
re: 10 step methodSilverKnight2004-04-19 18:02:43
re: AlgorithmSilverKnight2004-04-19 18:00:09
re(2): question for e.g.logischer Verstand2004-04-19 17:58:58
Solution10 step methodlogischer Verstand2004-04-19 17:58:17
SolutionAlgorithmPenny2004-04-19 17:52:44
Some ThoughtsA possible wayOskar2004-04-19 17:51:17
re: question for e.g.SilverKnight2004-04-19 17:49:00
Questionquestion for e.g.logischer Verstand2004-04-19 17:39:36
Some Thoughtsone wayLarry2004-04-19 16:47:15
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (10)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information