Ask Question

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.

+2
Answers (1)
  1. 30 June, 10:47
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers