Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Difficulty: 5/10
Date added: 29th of December 2009
In this exercise, you learn to replace for-loops by algorithms.
Reading the literature, one reads:
Prefer algorithms over loops [1][2] |
This is easier said than done.
In this exercise you must replace for-loops by using a combination of all those algorithm things like std::for_each, std::transform, std::bind1st, std::bind2nd, std::multiplies and more of the likes. It is up to you to find the correct combination.
The exercises are unordered. Some require Boost, but will be in namespace std after the C++11 standard.
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <cmath> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
int SumPositives(const std::vector<int>& v) |
Replace the for-loop. You will need:
int ProductNonZeroPositives(const std::vector<int>& v) |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
int SumFirst(const std::vector<std::pair<int,int> >& v) |
Replace the for-loop. You will need:
int SumSecond(const std::vector<std::pair<int,int> >& v) |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <vector> |
Replace the for-loop. You will need:
#include <cassert> |
Replace the BOOST_FOREACH. You will need:
#include <cassert> |
Replace the for-loop. You will need:
#include <cassert> |
Replace the for-loop. You will need:
#include <algorithm> |
Replace the for-loop. You will need:
#include <vector> |
Feel free to post your feedback about this exercise at Programmer's Heaven.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.