Informations

Auteur(s) Félix Ruyffelaere Anthony Doeraene
Date limite Pas de date limite
Limite de soumission Pas de limite

Etiquettes

Se connecter

Streams

You have to write 2 functions that will respectively map and filter a linked list in the same way that streams in java.

You will have to use the following structures in your code to represent linked lists:

typedef struct node {
  struct node *next;
  int value;
} node_t;

typedef struct list {
  struct node *first;
  int size;
} list_t;

Question 1: Map
/**
 * @brief Apply the function 'f' to all elements of the linked list.
 *
 * @param list: A pointer to the linked list.
 * @param f: A function that returns the new value to insert, generated from the old value
 */
void map(list_t *list, int (*f)(int));
Question 2: Filter
/**
 * @brief Filter a linked list according to the predicate 'f', which will return 0 if the node must be deleted, 1 otherwise.
 * Elements that don't match are thus deleted, don't forget to free the nodes when removing them from the linked list.
 * If none of the elements match the predicate, the first node of the list should be set to 'NULL'.
 *
 * @param list: A pointer to a linked list.
 * @param f: predicate, takes an int as argument and returns 1 if the value matches the predicate, 0 otherwise.
 */
void filter(list_t *list, int (*f)(int));