Question: accordingly. The function should return the removed element (12 in the previous example). If the list is empty, throw an exception. g. (5 pts)
accordingly. The function should return the removed element (12 in the previous example). If the list is empty, throw an exception. g. (5 pts) Write removeMin function that does not accept any parameter and removes the last element from the list. For instance, if the elements are [12, 9, 7, 5, 5, 3], the list elements will be [12, 9, 7, 5, 5] after calling removeMin function. You should only decrease the size (mySize) by one in this function. The function should return the removed element (3 in the previous example). If the list is empty, throw an exception. h. (5 pts) Write a function named display to print the elements in the list separated by a comma. E.g., [13,11,8,9,12]. Note that you should not print all array content, you should print the elements in the list. For instance, when you create an integer list with capacity 100, myArray will contain 100 zeros, but you should not display them. Therefore, you should iterate your loop from 0 to mySize-1. The function should return nothing. i. (5 pts) Write a function named at that accepts an integer parameter index and returns the element at the given index. If there is no element at that index, throw an exception. An example driver class (MyListDriver.cpp) and its output are given below. #include #include "MyList.h" using namespace std; int main() { } MyList a(3); MyList b(-10); cout < < "Size of a: < < a.getSize() < < endl; 11 cout < < "Capacity of a: < < a.getCapacity() < < endl; cout < < "Size of b: " < < b.getSize() < < endl; cout < < "Capacity of b: " < < b.getCapacity () < < endl; a.add(9); a.display(); a.add (2); a.display(); a.add(4); a.display(); a.add (3); a.display(); a.add(5); a.display(); a.add (1); a.display(); a.add(4); a.display(); a.add(10); a.display(); W 11 cout < < "a.getMin(): < < a.getMin() < < endl; cout < < "a.getMax(): < < a.getMax() < < < endl; cout < < "a.at(1): < < a.at(1) < < endl; cout < < "a.removeMin(): < < a.removeMin()
Step by Step Solution
3.42 Rating (149 Votes )
There are 3 Steps involved in it
template typename T T MyList T removeMin if mySize 0 throw stdruntimeerrorList is empt... View full answer
Get step-by-step solutions from verified subject matter experts
