Implement a generic (template) class called MArray. A generic class is a general
ID: 3842214 • Letter: I
Question
Implement a generic (template) class called MArray. A generic class is a general version of a class; it is a homogenous data structure that handles multiple data types. My will be similar to C++ vectors. The array size will grow dynamically when the user inserts an element to a full array. The class should not use vectors. Instead, you should use dynamic memory allocation (a dynamic array The class should have three member variables: myarray: the dynamic array sike the current size of the array used the number of elements currently used in the array The class should have the following functionalities: A default constructor that initializes the size of the array to 5 elements A default destructor that frees the dynamic memory that was allocated. int length() a method that returns an integer value indicating the number of elements currently used in the array. void insert Headltem a method that inserts a new item making it the first element in the array. If the array is full, then a new dynamic array of double the size should replace the existing array and the items in the old array are copied to the new array. void insert Tail tem i a method that inserts a new item making it the last element in the array. If the array is full, then a new dynamic array of double the size should replace the existing array. void delete Head() deletes the first element in the array. void delete Tail() deletes the last element in the array. void sortAscending() sorts the elements of the array in ascending order. Use bubblesort to o that. void sortDescending() sorts the elements of the array in descending order Use bubblesort to do that. Item getMax() returns the maximum value in the array. Item get Min() returns the minimum value in the array. C++ allows the overloading of the [J operator. This feature makes it possible to access an element in a MLAnay object in an array-like behavior. Overload this operator and make sure to have boundary checks using assertions. Ifthe user tries toaccess an element outside the range of the array or at a location that is not used yet then an error message should be displayed on the screen.Explanation / Answer
var a = new Array(1,2,3,4,5); a[0] // returns 1 a.length // returns 5 ------------------- int[] a = new int[10]; ------------------------ a.pop(); // returns last object of array, removes it a.push(20); // puts 20 as the last element of the array, returns length a.shift(); // returns first object of the array, removes it a.unshift(30); // puts 30 as the first element of the array, returns length
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.