// 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
t_btree *insert(t_btree *node, void *item, int (*cmp)())
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 42 Exam Rank 03
// Code in /rendu/ex00/ft_list_size.c // Test locally with a main (not submitted) // Submit
void *search(t_btree *node, void *ref, int (*cmp)())
// remove from front
t_list *current = *begin_list; t_list *previous = NULL; while (current)
if (!*root) *root = ft_btree_create_node(item); return; if (cmpf(item, (*root)->item) < 0) ft_btree_insert_data(&(*root)->left, item, cmpf); else ft_btree_insert_data(&(*root)->right, item, cmpf);
Good luck, and may your pointers never be dangling! // Handle special cases: INT_MIN, base 10, base 16, etc
t_btree *node; struct s_queue *next; t_queue; void enqueue(t_queue **q, t_btree *node)
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;
| Exercise | Difficulty | Data Structure | Recursion Required? | |----------|------------|----------------|----------------------| | ft_list_size | Easy | Singly linked list | No (iterative) | | ft_list_push_back | Easy | Singly linked list | No | | ft_list_last | Easy | Singly linked list | No | | ft_list_foreach | Easy | Singly linked list | No | | ft_list_remove_if | Medium | Singly linked list | No | | ft_list_reverse | Medium | Singly linked list | No | | ft_list_sort | Medium-Hard | Singly linked list | Optional | | ft_list_merge | Medium | Singly linked list | No | | ft_itoa_base | Medium | String (no struct) | No (but tricky) | | ft_atoi_base | Medium | String (no struct) | No | | ft_split_whitespaces | Easy | String → array | No | | ft_range | Easy | Array | No | | ft_ultimate_range | Easy | Array | No | | ft_strjoin | Easy | String | No | | ft_btree_create_node | Easy | Binary tree | No | | ft_btree_apply_prefix | Medium | Binary tree | Yes | | ft_btree_apply_infix | Medium | Binary tree | Yes | | ft_btree_apply_suffix | Medium | Binary tree | Yes | | ft_btree_insert_data | Hard | Binary tree | Yes | | ft_btree_search_item | Medium | Binary tree | Yes | | ft_btree_level_count | Medium | Binary tree | Yes | | ft_btree_apply_by_level | Hard | Binary tree | Yes (with queue) | When you start Rank 03: Unlike a school exam where you memorize facts,
Introduction: What is Exam Rank 03? Exam Rank 03 is the third of five progressively difficult exams in the 42 curriculum (following Rank 00 and Rank 01, preceding Rank 04 and Rank 05). Unlike a school exam where you memorize facts, the 42 exam is a practical coding test in a restricted environment.