Arrayrotate: //create A Class of Arrayrotate
Arrayrotate: //create A Class of Arrayrotate
using System.Collections;
//create a class of ArrayRotate
class ArrayRotate
{
ArrayList b = new ArrayList();
}
get
{
return b;
}
}
//Here we use a Constructor,to initialize values
public ArrayRotate()
{
A[0] = 1;
A[1] = 2;
A[2] = 3;
A[3] = 4;
A[4] = 5;
A[5] = 6;
A[6] = 7;
A[7] = 8;
A[8] = 9;
A[9] = 10;
}
public void RotateRight(ArrayList AA, int n)
{
for (int j = 0; j < A.Count; j++)
A[j] = AA[j];
for (int h = A.Count - 1; h > 6; h--)
{
int last = A[9], i;
for (i = A.Count - 1; i > 0; i--)
{
A[i] = A[i - 1];
A[i - 1] = last;
}
}
}
public void RotateLeft(ArrayList AA, int n)
{
for (int j = 0; j < A.Count; j++)
A[j] = AA[j];
for (int h = 0; h < 3; h++)
{
int last = A[0], i;
for (i = 0; i < A.Count - 1; i++)
A[i] = A[i + 1];
A[A.Count - 1] = last;
}
}
//~ArrayRotate()
// {
}
class RotateArrays
{
static void Main(string[] args)
{
ArrayRotate obj = new ArrayRotate();
obj.displayArray();
// Console.WriteLine("\nrotate right");
// obj.RotateRight(obj.A, 3);
// obj.displayArray();
Console.WriteLine("\nrotate left");
obj.RotateLeft(obj.A, 3);
obj.displayArray();