582484 Algorithm Libraries

Exercise 4


  1. Write variants of the reverse_word_order algorithm from Exercise 2 (see solution) so that the instead of a single separator value the algorithm gets
    1. a range of values, all of which are separators.
    2. a unary predicate for recognizing separators.
  2. Use for_each to add a newline character '\n' to the end every string in a container of strings.
    1. Write your own functor.
    2. Use only standard functor adaptors (Hint: push_back).
  3. Write a unary functor that as an argument to the transform algorithm transforms a value into the average of the value and the last few values before it. This achieves a similar (but not identical) smoothing effect as the smooth_iterator from Exercise 1.