aspon bod prosim

This commit is contained in:
Michal Utľák 2024-03-10 16:59:32 +01:00
parent 204b2ec003
commit 87e1e23e2f

View File

@ -129,6 +129,22 @@ list_element_t foldl_list(list_t *list, list_element_t initial,
return accumulator; 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) { list_t *reverse_list(list_t *list) {
if (!list) { if (!list) {
return NULL; return NULL;