static void Main(string[] args) { // ---------------------------------------- Using created Array class ---------------------------------------- // Create an object of the Array class Array numbers = new Array(3); // insert method numbers.Insert(10); numbers.Insert(20); numbers.Insert(30); numbers.Insert(40); // removeAt method numbers.RemoveAt(3); // indexOf method Console.WriteLine(numbers.IndexOf(10)); // print method numbers.Print(); // printArray method numbers.PrintArray(); // ---------------------------------------- Exercises ---------------------------------------- // max method Console.WriteLine(numbers.Max()); // intersect method // Create a new array to compare Array newNums = new Array(5); newNums.Insert(10); newNums.Insert(20); newNums.Insert(40); newNums.Insert(50); newNums.Insert(60); Console.WriteLine("\nnewNums"); newNums.PrintArray(); numbers.Intersect(newNums).PrintArray(); // reverse method numbers.Reverse(); numbers.PrintArray(); Array nullArr = new Array(0); nullArr.Reverse(); nullArr.PrintArray(); // insertAt method numbers.InsertAt(15, 2); numbers.PrintArray(); } // Main method
} // Intersect method public Array Intersect2(Array other) { Array intersection = new Array(count); foreach (int item in items) { if (other.IndexOf(item) >= 0) { intersection.Insert(item); } } return(intersection); } // Intersect2 method
} // Max method // 2 - Extend the Array class and add a method to return the common items in this array and another array. public Array Intersect(Array otherArr) { Array common = new Array(1); for (int i = 0; i < this.count - 1; i++) { for (int j = 0; j < otherArr.count; j++) { if (items[i] == otherArr.items[j]) { common.Insert(items[i]); } } } return(common); } // Intersect method