News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Using the list as a container for double value

Started by aruljothi, Jun 11, 2009, 05:41 PM

Previous topic - Next topic

aruljothi

#include <iostream>
#include <list>
#include <numeric>
using namespace std;

void print(const list<double> &lst)
{               
   list<double>::const_iterator p;

   for (p = lst.begin();
        p !=lst.end(); ++p)
      cout << *p << endl;
   cout << endl;
}

int main()
{
   double w[4] = { 0.9, 0.8, 88, -99.99 };
   list<double> z;

   for( int i = 0; i < 4; ++i)
      z.push_front(w);
   print(z);
   z.sort();
   print(z);
   cout << "sum is "
        << accumulate(z.begin(), z.end(), 0.0)
        << endl;
}