(Please Use c++ Code) Using a template, create a class Mlist which will handle d
ID: 3862539 • Letter: #
Question
(Please Use c++ Code)
Using a template, create a class Mlist which will handle different type objects. An mlist is a list of objects (numbers, strings, etc) which has functions which allow additions to the front, and back of the list, removals from the front and back of the list, and removals from anywhere in the list. The accessor functions will return the front and end of the list, and will tell if an object is in the list. We will use iterators as well as recursion to implement the class. Also, create and implement the template class Mlist. INCLUDE a main program that creates an Mlist and tests each function.
Begin by creating the template class with the following interface :
Explanation / Answer
int main()
{
Mlist<int> testfun1 = Mlist<int>;
testfun1.add(1);
testfun1.add(5);
testfun1.add(4);
testfun1.add(3);
testfun1.remove(5);
cout<< testfun1.front()<<endl;
cout<<testfun1.back()<<endl;
Mlist<string> testfun2 = Mlist<string>();
testfun2.add("Bob");
testfun2.add("Alice");
testfun2.add("Charlie");
testfun2.add("Dolly");
testfun2.remove("Dolly");
cout<<testfun2.front()<<endl;
cout<<testfun2.back()<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.