42 Exam 05

The content of Exam 05 could vary widely, but if it's like many 42 exams, it might involve:


Because you cannot allocate an array, you must use O(n²) pointer swapping.

Step 1: Handle nulls

if (!begin_list || !*begin_list) return ;

Step 2: The swap logic You need a temporary pointer to swap node contents. However, swapping data is easier than swapping next pointers. (Note: In 42 exam 05, swapping data is allowed because the subject doesn't forbid it. Swapping pointers is for purists.) 42 exam 05

Step 3: Implementation

void ft_list_sort(t_list **begin_list, int (*cmp)())

Why this passes 42 Exam 05:


Before your exam date, make sure you have reviewed:

During the exam, the automated grading system (Moulinette) is strict. Here are the common reasons for failure:

  • Compilation Flags: The exam compiles with -Wall -Wextra -Werror. Your code must not throw any warnings.
  • Header Guards: Missing #ifndef, #define, #endif in header files will cause compilation errors if files are included multiple times.
  • Memory Leaks: Even though C++ has destructors, you must manually delete anything you new. Using tools like valgrind during practice is essential.

  • Operator Overloading: Specifically overloading << for output and comparison operators (==, !=, >, <).
  • You cannot Google "how to use strcmp." You must do: The content of Exam 05 could vary widely,

    man strcmp
    

    Practice reading man pages for:

    Before submitting, always attempt to compile your code locally using the strict flags: c++ -Wall -Wextra -Werror -std=c++98 main.cpp <your_files>.cpp


    | Pitfall | Solution | | :--- | :--- | | "My program works 90% of the time, but fails randomly." | That's a race condition. Add mutexes around EVERY shared variable access. | | "I get a deadlock after two minutes." | You forgot to unlock a mutex in one error path. Use pthread_mutex_unlock before every return or exit. | | "Moulinette says 'Segmentation fault' but my local machine runs fine." | You probably used a library function not allowed (printf inside a signal handler? No). Or you failed to initialize a semaphore pointer. | | "I passed the first two exercises, but the third is impossible." | Strategy: Get partial points. If you cannot solve the full producer-consumer, at least initialize all semaphores and create the threads. Moulinette grades per test case. | Because you cannot allocate an array, you must