/********************************************************************** Chapter: 7 Templates Generic Programming and STL C++ for C Programmers, Edition 3 By Ira Pohl ********************************************************************/ #include #include // for algorithm "accumulate" #include // for container "list" using namespace std; //Using the list container void print( list &lst) { //using an iterator to traverse lst list::iterator p; for (p = lst.begin(); p !=lst.end(); ++p) cout << *p << '\t'; cout << endl; } int main() { double w[5] = { 0.97, 0.81, 88, -99.99, 3.14 }; list z; for (int i = 0; i < 5; ++i) z.push_front(w[i]); print(z); z.sort(); print(z); cout << "sum is " << accumulate(z.begin(), z.end(), 0.0) << endl; int look; cin >> look; }