(list)+map function
void return, just maps f onto every value in the linked list till nullity.
This commit is contained in:
9
list.cpp
9
list.cpp
@@ -54,6 +54,15 @@ List<T> *reverse(List<T> *lst, List<T> *prev = nullptr)
|
|||||||
return reverse(next, lst);
|
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>
|
template <typename T>
|
||||||
std::ostream& operator<<(std::ostream& ostream, const List<T> *lst)
|
std::ostream& operator<<(std::ostream& ostream, const List<T> *lst)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user