Ask Question
3 November, 19:57

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.

+5
Answers (1)
  1. 3 November, 22:48
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers