Answer:
See explaination
Explanation:
#include <iostream>
#include <iterator>
#include <list>
using namespace std;
list <int> :: iterator maxLoc(list<int>& alist){
list<int> :: iterator max;
list<int> :: 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 <char> :: iterator maxLoc(list<char>& alist){
list<char> :: iterator max;
list<char> :: 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 <int> intlist(intArr, intArr + intSize);
list<int> :: iterator it;
for(int i = 0;i<intSize;i++){
list<int> :: iterator m = maxLoc(intlist);
cout << *m << endl;
}
char chrArr[] = "Hello World!";
int chrSize = sizeof(chrArr);
list<char> chrlist(chrArr, chrArr + chrSize);
for(int j = 0;j<chrSize;j++){
list<char> :: iterator m = maxLoc(chrlist);
cout << *m << endl;
}
}