/// G. Hagopian PPP8 ex 11

/** 11. Write a function that finds the smallest and the largest
element of a vector argument and also computes the mean and the median.
Do not use global variables. Either return a struct containing the
results or pass them back through reference arguments. Which of the
two ways of returning several result values do you prefer and why?
*/

#include "std_lib_facilities.h"

struct Min_max {
    string maximum;
    string minimum;
    ///Min_max() {};
    Min_max(string mi, string ma) : maximum(ma), minimum(mi) { }
};

void minimax(vector<string> v, string& mx, string& mn) {
    for(string s : v) {
        if(s<mn) mn=s;
        if(s>mx) mx=s;
    }
}

Min_max minimax(vector<string> v) {
    string mini{v[0]};
    string maxi{v[0]};

    for(string s : v) {
        if(s<mini) mini=s;
        if(s>maxi) maxi=s;

    }
    /*cout << "\nmini = " << mini
             << "\nmaxi = " << maxi;
        cin.get();*/
    Min_max mm(mini,maxi);
    return mm;
}

int main() {
    Min_max mm("","");
    ifstream inf("eap.txt");
    string s;
    vector<string> vs;
    string mn, mx;
    while(inf>>s)
        vs.push_back(s);
    minimax(vs, mx, mn);
    cout << "\nminimum = " << mn
         << "\nmaximum = " << mx;
    cin.get();
    sort(vs.begin(),vs.end());
    while(vs[0]=="")
        vs.erase(vs.begin(),vs.begin()+1);

    mm = minimax(vs);
    cout << "\nGot here.";
    cin.get();

    cout << "\nminimum = " << mm.minimum
         << "\nmaximum = " << mm.maximum;

}
