Ask Question
13 May, 07:13

Implement the function maxLoc (), which returns an iterator at the largest element in a list. template typename list::iterator maxLoc (list& aList); Write a program that tests maxLoc (), using the following declarations: int intArr[] = {23, 49, - 3, 29, 17, 200, 38, 93, 40}; int intSize = sizeof (intArr) / sizeof (int); list intList (intArr, intArr+intSize); char chrArr[] = "Hello World!"; int chrSize = sizeof (chrArr); list chrList (chrArr, chrArr+chrSize); The program should repeatedly call maxLoc (), output the largest value, and then delete the value, until the list is empty.

+4
Answers (1)
  1. 13 May, 08:16
    0
    See explaination

    Explanation:

    #include

    #include

    #include

    using namespace std;

    list : : iterator maxLoc (list& alist) {

    list : : iterator max;

    list : : iterator it;

    int maxs = - 199999999;

    for (it = alist. begin (); it! = alist. end (); it++) {

    int c = * it;

    if (maxs < c) {

    max = it;

    maxs = * it;

    }

    }

    alist. erase (max);

    return max;

    }

    list : : iterator maxLoc (list& alist) {

    list : : iterator max;

    list : : iterator it;

    int maxs = - 199999999;

    for (it = alist. begin (); it! = alist. end (); it++) {

    char c = * it;

    if (maxs < c) {

    max = it;

    maxs = * it;

    }

    }

    alist. erase (max);

    return max;

    }

    int main () {

    int intArr[] = {23, 49, - 3, 29, 17, 200, 38, 93, 40};

    int intSize = sizeof (intArr) / sizeof (int);

    list intlist (intArr, intArr + intSize);

    list : : iterator it;

    for (int i = 0; i
    list : : iterator m = maxLoc (intlist);

    cout << * m << endl;

    }

    char chrArr[] = "Hello World!";

    int chrSize = sizeof (chrArr);

    list chrlist (chrArr, chrArr + chrSize);

    for (int j = 0; j
    list : : iterator m = maxLoc (chrlist);

    cout << * m << endl;

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Implement the function maxLoc (), which returns an iterator at the largest element in a list. template typename list::iterator maxLoc ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers