0% found this document useful (0 votes)
23 views2 pages

Arrayrotate: //create A Class of Arrayrotate

The document defines a class called ArrayRotate that can rotate an array of numbers to the left or right by a specified number of positions. It initializes an array with numbers 1 through 10, defines methods to rotate the array left or right and display the rotated array, and includes a Main method that demonstrates rotating the array 3 positions to the left and displaying the result.

Uploaded by

Umer Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Arrayrotate: //create A Class of Arrayrotate

The document defines a class called ArrayRotate that can rotate an array of numbers to the left or right by a specified number of positions. It initializes an array with numbers 1 through 10, defines methods to rotate the array left or right and display the rotated array, and includes a Main method that demonstrates rotating the array 3 positions to the left and displaying the result.

Uploaded by

Umer Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections;
//create a class of ArrayRotate
class ArrayRotate
{
ArrayList b = new ArrayList();

//Property of data member


public ArrayList A
{
set
{
if (b.Count == 0)
{
Console.WriteLine("Please enter a number");
}
b = value;

}
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;
}
}

public void displayArray()


{
Console.WriteLine("Array is");
for (int i = 0; i < 10; i++)
{
Console.Write(A[i] + "\t");
}

//~ArrayRotate()
// {

// Console.WriteLine("Destructor called ");


// A=null;
// }

}
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();

You might also like