Using the list as a container for double value : list « List « C++






Using the list as a container for double value

  
#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[i]);
   print(z);
   z.sort();
   print(z);
   cout << "sum is "
        << accumulate(z.begin(), z.end(), 0.0)
        << endl;
}
  
    
  








Related examples in the same category

1.Instantiating an STL List of Integers
2.Use generic list to create a list of chars
3.Use generic list to create list of strings
4.Store class objects in a listStore class objects in a list
5.Store class objects with overloaded operators in a list.
6.Use std::copy to print all elements in a list
7.Pass list to a function
8.Uses ostream_iterator and copy algorithm to output list elements
9.Add elements in a multiset to a list
10.access list
11.Comparison Algorithms
12.Add elements in a set to a list
13.Merge two lists.Merge two lists.