diff options
-rw-r--r-- | list.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -76,6 +76,16 @@ T reduce(List<T> *lst, T (*reducer) (T, T), T init = 0) } template <typename T> +List<T> *filter(List<T> *lst, bool (*f)(T), List<T> *new_lst = nullptr) +{ + if (!lst) + return new_lst; + if (f(lst->value)) + new_lst = append(new_lst, lst->value); + return filter(lst->next, f, new_lst); +} + +template <typename T> std::ostream& operator<<(std::ostream& ostream, const List<T> *lst) { if (!lst) |