From 87e1e23e2f7bf21c5091c75cc8e135232a927140 Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Sun, 10 Mar 2024 16:59:32 +0100 Subject: [PATCH] aspon bod prosim --- cv4/list_ops.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cv4/list_ops.c b/cv4/list_ops.c index d27b5de..1de4a79 100644 --- a/cv4/list_ops.c +++ b/cv4/list_ops.c @@ -129,6 +129,22 @@ list_element_t foldl_list(list_t *list, list_element_t initial, return accumulator; } +list_element_t foldr_list(list_t *list, list_element_t initial, + list_element_t (*foldr)(list_element_t, + list_element_t)) { + if (!list || !foldr) { + return initial; + } + + list_element_t result = initial; + + for (size_t i = 0; i < list->length; ++i) { + result = foldr(list->elements[list->length - 1 - i], result); + } + + return result; +} + list_t *reverse_list(list_t *list) { if (!list) { return NULL;