Consider the template class List presented in the course (slide set “Templates”,
section “Generic Lists”). Write a template function read such that the following
operation becomes possible:
bool isend(double x) { return x == 0; }
List<double> l;
int n = read<double,isend>(l);
The function reads a sequence of items x1, . . . , xn+1 such that n + 1 is the smallest index i
for which isend(xi) returns true; the function puts the elements x1, . . . , xn (in the order
in which they were read) into l. The result of the function is n, if everything went okay,
and −1, if an error occurred. The function needs time O(n).
You may modify the definition of List, e.g. by adding new data members and/or member
functions (please indicate your changes clearly); in particular, since new elements are to
be added at the end of the list, it is recommended to keep track of its last element.
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment