42 Exam Rank 03 99%

| 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)

t_list *current = *begin_list; t_list *previous = NULL; while (current)

int count = 0; while (begin_list) count++; begin_list = begin_list->next; return (count);

Good luck, and may your pointers never be dangling! 42 Exam Rank 03

// add to end

Forgetting that base can be 2, 8, 10, 16, but not 1 or >16 per subject. Also, value can be negative only for base 10. 4. ft_btree_insert_data (Hard) void ft_btree_insert_data(t_btree **root, void *item, int (*cmpf)())

typedef struct s_queue

> 1 (to start ex00)

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;

if (!node) return; // do something with node traverse(node->left); traverse(node->right); // Recursive approach: // - Convert absolute value

// Handle special cases: INT_MIN, base 10, base 16, etc. // Recursive approach: // - Convert absolute value // - Build string from least significant digit // - Handle negative for base 10

int max(int a, int b) return (a > b ? a : b); int ft_btree_level_count(t_btree *root)

Total: 10/8. PASS.

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);