# Array Rotations Data Structure Solution

Page Contents

## Array Rotations

Program for array rotation
An array is an aggregate data structure to store a group of objects of the same or different types.Array can hold primitive as well as references. The array is the most efficient data structure for sorting and accessing a sequence of objects.

In this lesson we will rotate an array arr[] of n elements by d. d is the number of rotations.To rotate array by one we will store arr in a temporary variable temp,move arr to arr,arr to arr …and finally temp to arr[n-1].

Let us take the same example arr[] = [1, 2, 3, 4, 5, 6, 7], d =  3
Rotate arr[] by one  3 times
We get [2, 3, 4, 5, 6, 7, 1] after first rotation and [ 3, 4, 5, 6, 7, 1, 2] after second rotation and finally [4, 5, 6, 7, 1, 2, 3,] after third rotation

Code :
#include
using namespace std;
int main()
{
int arr={0},n,i,j,t;
while(1)
{
cout < arr[i];
cout  n;
for(i=0;i<n;i++)
{
t=arr;
for(j=0;j<6;j++)
{
arr[j]=arr[j+1];
}
arr[j]=t;
}
for (i=0;i<7;i++)
cout << arr[i] << ” “;
cout << endl;
}
return 0;
}