Answer to Question #322821 in C# for naina

Question #322821

Write a C# Program to rotate an Array of size 10 in left and right Direction three times Create a Class of ArrayRotate with data member of integer type array of size 10, property of that member, all constructors, destructor, user define displayArray() Method, RotateLeft(int[] arr) Method, RotateRight(int[] arr) Method. Then test the functionality of Class in the Driver Class of RotateArray.

1
Expert's answer
2022-04-03T07:59:41-0400
 class ArrayRotate
    {
        ArrayList array;




        public ArrayList Array
        {
            get
            {
                return array;
            }
            set
            {
                array = value;
            }
        }
        public ArrayRotate(ArrayList array)
        {
            this.array = array;
        }




        ~ArrayRotate()
        {
            array = null;
        }




        public void DisplayArray()
        {
            Console.Write("Your array:");
            foreach (var item in array)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine();
        }




        public void RotateLeft()
        {
            for (int i = 0; i < 3; i++)
            {
                int temp = (int)array[0];


                for (int j = 0; j < array.Count - 1; j++)
                    array[j] = array[j + 1];


                array[array.Count - 1] = temp;
            }
        }




        public void RotateRight()
        {
            for (int i = 0; i < 3; i++)
            {
                int temp = (int)array[array.Count - 1];


                for (int j = array.Count - 1; j > 0; j--)
                    array[j] = array[j - 1];


                array[0] = temp;
            }
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            ArrayRotate arrayRotate = new ArrayRotate(new ArrayList { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            arrayRotate.DisplayArray();
            arrayRotate.RotateLeft();
            arrayRotate.DisplayArray();
            arrayRotate.RotateRight();
            arrayRotate.DisplayArray();
            Console.ReadKey();
        }




    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS