diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-11-22 05:53:07 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-11-22 05:53:07 +0000 |
commit | f4b08ddada8ff3865056138e900ebe966d870961 (patch) | |
tree | e786e6d9f0bcfc666ac9662582c9ffc1813f64ff /list.cpp | |
parent | 1537bb705bc7952fe8a0c94cacc9c434cba8d23d (diff) | |
download | algorithms-f4b08ddada8ff3865056138e900ebe966d870961.tar.gz algorithms-f4b08ddada8ff3865056138e900ebe966d870961.tar.bz2 algorithms-f4b08ddada8ff3865056138e900ebe966d870961.zip |
(list)+map function
void return, just maps f onto every value in the linked list till
nullity.
Diffstat (limited to 'list.cpp')
-rw-r--r-- | list.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -54,6 +54,15 @@ List<T> *reverse(List<T> *lst, List<T> *prev = nullptr) return reverse(next, lst); } +template <typename T, typename U> +void map(List<T> *lst, U (*f)(T)) +{ + if (!lst) + return; + lst->value = f(lst->value); + map(lst->next, f); +} + template <typename T> std::ostream& operator<<(std::ostream& ostream, const List<T> *lst) { |