42 Exam Rank 03 -

Do not use recursion here — unnecessary and slower. 2. ft_list_remove_if (Medium) void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)())

if (cmp(current->data, data_ref) == 0) if (previous) previous->next = current->next; else *begin_list = current->next; free(current); current = previous ? previous->next : *begin_list; else previous = current; current = current->next;

// Code in /rendu/ex00/ft_list_size.c // Test locally with a main (not submitted) // Submit

EXAM STARTED. You have 4h00.

Good luck, and may your pointers never be dangling!

Total: 6/8. Need 2 more points.

| Mistake | Consequence | Prevention | |---------|------------|------------| | Forgetting to include #include <stdlib.h> | Implicit function declaration → Moulinette fails | Write includes at top | | Memory leak in list remove_if | Fails strict test | Always free removed node | | Not handling NULL input | Segmentation fault in tests | Check if (!list) return | | Using recursion for deep lists | Stack overflow (not tested but bad style) | Use iteration for long lists | | Modifying original pointer without pointer-to-pointer | Head lost | Use t_list ** when head can change | | ft_itoa_base INT_MIN bug | Wrong output for -2147483648 | Special case: convert to unsigned | | Not checking base bounds | Undefined behavior → fails | if (base < 2 \|\| base > 16) return (NULL); | Recursion Cheat Sheet for Rank 03 Pattern 1: Traversal (no return value) void traverse(t_btree *node) 42 Exam Rank 03

if (!node) return (ft_btree_create_node(item)); if (cmp(item, node->item) < 0) node->left = insert(node->left, item, cmp); else node->right = insert(node->right, item, cmp); return (node);

struct s_list *next; void *data; t_list; typedef struct s_btree

Total: 10/8. PASS.

typedef struct s_queue

> 2 Available exercises: ex00: ft_list_size (2 pts) ex01: ft_btree_insert_data (4 pts) ex02: ft_itoa_base (4 pts)

t_btree *insert(t_btree *node, void *item, int (*cmp)()) Do not use recursion here — unnecessary and slower