From f4b08ddada8ff3865056138e900ebe966d870961 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 22 Nov 2021 05:53:07 +0000 Subject: (list)+map function void return, just maps f onto every value in the linked list till nullity. --- list.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/list.cpp b/list.cpp index 83e7068..df8cc13 100644 --- a/list.cpp +++ b/list.cpp @@ -54,6 +54,15 @@ List *reverse(List *lst, List *prev = nullptr) return reverse(next, lst); } +template +void map(List *lst, U (*f)(T)) +{ + if (!lst) + return; + lst->value = f(lst->value); + map(lst->next, f); +} + template std::ostream& operator<<(std::ostream& ostream, const List *lst) { -- cgit v1.2.3-13-gbd6f