Rotate Array by N Position - Via Programming Pearls
Lately, I have been trying to finish reading the Programming Pearls written by John Bentley. The chapters related with designing and developing algorithms are really entertaining. One of the questions that was discussed in the early chapters of the book was about an algorithm of rotating a one-dimensional vector, and I want to share my solution written in VB.NET and C# by utilizing a simple string array.
Question (with the terms of an array)
Rotate a one-dimensional array of K elements from left by N positions.
For instance, with K=7 and N=3, the array {a, b, c, d, e, f, g} is rotated to {d, e, f, g, a, b, c}.
Solution
As suggested in the book, I will be using the Array.Reverse method. I will also write the function that rotates an array from right as well in order to carry out the discussion further.
In VB.NET - Rotate By N From Left

In C# - Rotate By N From Left

In VB.NET - Rotate By N From Right

In C# - Rotate By N From Right

Page_Load of an ASP.NET environment would be a good place to test and visualize the results in this case.
In VB.NET

In C#

Finally, results on the browser should be like:
