C Piscine: Abstract: This Document Is The Subject For Day11 of The C Piscine at 42
C Piscine: Abstract: This Document Is The Subject For Day11 of The C Piscine at 42
Day 11
Staff 42 [email protected]
Abstract: This document is the subject for Day11 of the C Piscine @ 42.
Contents
I Instructions 2
II Foreword 4
IV Exercice 01 : ft_list_push_back 7
V Exercice 02 : ft_list_push_front 8
VI Exercice 03 : ft_list_size 9
IX Exercice 06 : ft_list_clear 12
X Exercice 07 : ft_list_at 13
XI Exercice 08 : ft_list_reverse 14
XV Exercice 12 : ft_list_remove_if 18
XX Exercice 17 : ft_sorted_list_merge 23
1
Chapter I
Instructions
• Watch out! This document could potentially change up to an hour before submis-
sion.
• Make sure you have the appropriate permissions on your files and directories.
• On top of that, your exercises will be checked and graded by a program called
Moulinette.
• Moulinette is very meticulous and strict in its evaluation of your work. It is entirely
automated and there is no way to negotiate with it. So if you want to avoid bad
surprises, be as thorough as possible.
• Moulinette is not very open-minded. It won’t try and understand your code if it
doesn’t respect the Norm. Moulinette relies on a program called Norminator to
check if your files respect the norm. TL;DR: it would be idiotic to submit a piece
of work that doesn’t pass Norminator’s check.
• These exercises are carefully laid out by order of difficulty - from easiest to hardest.
We will not take into account a successfully completed harder exercise if an easier
one is not perfectly functional.
• Using a forbidden function is considered cheating. Cheaters get -42, and this grade
is non-negotiable.
2
C Piscine Day 11
• Moulinette compiles with these flags: -Wall -Wextra -Werror, and uses gcc.
• You cannot leave any additional file in your directory than those specified in the
subject.
• Got a question? Ask your peer on your right. Otherwise, try your peer on your
left.
• Check out the "C Piscine" part of the forum on the intranet.
• Examine the examples thoroughly. They could very well call for details that are
not explicitly mentioned in the subject...
• For the following exercises, you have to use the following structure :
• You’ll have to include this structure in a file ft_list.h and submit it for each
exercise.
• From exercise 01 onward, we’ll use our ft_create_elem, so make arrangements (it
could be useful to have its prototype in a file ft_list.h...).
3
Chapter II
Foreword
SPOILER ALERT
DON’T READ THE NEXT PAGE
4
C Piscine Day 11
• In Fight Club, Tyler Durden and the narrator are the same person.
• In The others, the inhabitants of the house are ghosts and vice-versa.
• In The Village, monsters are the villagers and the movie actually takes place in
our time.
• In Game of thrones, Robb Stark and Joffrey Baratheon die on their wedding day.
• In Stargate SG-1, Season 1, Episode 18, O’Neill and Carter are in Antartica.
5
Chapter III
Exercice 00 : ft_create_elem
Exercice : 00
ft_create_elem
Turn-in directory : ex00/
Files to turn in : ft_create_elem.c, ft_list.h
Allowed functions : malloc
Remarks : n/a
• Create the function ft_create_elem which creates a new element of t_list type.
6
Chapter IV
Exercice 01 : ft_list_push_back
Exercice : 01
ft_list_push_back
Turn-in directory : ex01/
Files to turn in : ft_list_push_back.c, ft_list.h
Allowed functions : ft_create_elem
Remarks : n/a
• Create the function ft_list_push_back which adds a new element of t_list type
at the end of the list.
7
Chapter V
Exercice 02 : ft_list_push_front
Exercice : 02
ft_list_push_front
Turn-in directory : ex02/
Files to turn in : ft_list_push_front.c, ft_list.h
Allowed functions : ft_create_elem
Remarks : n/a
• Create the function ft_list_push_front which adds a new element of type t_list
to the beginning of the list.
8
Chapter VI
Exercice 03 : ft_list_size
Exercice : 03
ft_list_size
Turn-in directory : ex03/
Files to turn in : ft_list_size.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_size which returns the number of elements in the
list.
9
Chapter VII
Exercice 04 : ft_list_last
Exercice : 04
ft_list_last
Turn-in directory : ex04/
Files to turn in : ft_list_last.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_last which returns the last element of the list.
10
Chapter VIII
Exercice 05 : ft_list_push_params
Exercice : 05
ft_list_push_params
Turn-in directory : ex05/
Files to turn in : ft_list_push_params.c, ft_list.h
Allowed functions : ft_create_elem
Remarks : n/a
• Create the function ft_list_push_params which creates a new list that includes
command-line arguments.
11
Chapter IX
Exercice 06 : ft_list_clear
Exercice : 06
ft_list_clear
Turn-in directory : ex06/
Files to turn in : ft_list_clear.c, ft_list.h
Allowed functions : free
Remarks : n/a
• Create the function ft_list_clear which clears all links from the list.
12
Chapter X
Exercice 07 : ft_list_at
Exercice : 07
ft_list_at
Turn-in directory : ex07/
Files to turn in : ft_list_at.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_at which returns the Nth element of the list.
13
Chapter XI
Exercice 08 : ft_list_reverse
Exercice : 08
ft_list_reverse
Turn-in directory : ex08/
Files to turn in : ft_list_reverse.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_reverse which reverses the order of a list’s elements.
You may only use pointers related stuff.
14
Chapter XII
Exercice 09 : ft_list_foreach
Exercice : 09
ft_list_foreach
Turn-in directory : ex09/
Files to turn in : ft_list_foreach.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
(*f)(list_ptr->data);
15
Chapter XIII
Exercice 10 : ft_list_foreach_if
Exercice : 10
ft_list_foreach_if
Turn-in directory : ex10/
Files to turn in : ft_list_foreach_if.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), void *data_ref, int (*cmp)())
(*f)(list_ptr->data);
(*cmp)(list_ptr->data, data_ref);
16
Chapter XIV
Exercice 11 : ft_list_find
Exercice : 11
ft_list_find
Turn-in directory : ex11/
Files to turn in : ft_list_find.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_find which returns the address of the first link, whose
data is "equal" to the reference data.
17
Chapter XV
Exercice 12 : ft_list_remove_if
Exercice : 12
ft_list_remove_if
Turn-in directory : ex12/
Files to turn in : ft_list_remove_if.c, ft_list.h
Allowed functions : free
Remarks : n/a
• Create the function ft_list_remove_if which erases off the list all elements, whose
data is "equal" to the reference data.
18
Chapter XVI
Exercice 13 : ft_list_merge
Exercice : 13
ft_list_merge
Turn-in directory : ex13/
Files to turn in : ft_list_merge.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_merge which places elements of a list begin2 at the
end of an other list begin1.
19
Chapter XVII
Exercice 14 : ft_list_sort
Exercice : 14
ft_list_sort
Turn-in directory : ex14/
Files to turn in : ft_list_sort.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_sort which sorts the list’s contents by ascending order
by comparing two links thanks to a function that can compare the data held in those
two links.
20
Chapter XVIII
Exercice 15 : ft_list_reverse_fun
Exercice : 15
ft_list_reverse_fun
Turn-in directory : ex15/
Files to turn in : ft_list_reverse_fun.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
• Create the function ft_list_reverse_fun which reverses the order of the elements
of the list. You may only use pointers related stuff.
21
Chapter XIX
Exercice 16 : ft_sorted_list_insert
Exercice : 16
ft_sorted_list_insert
Turn-in directory : ex16/
Files to turn in : ft_sorted_list_insert.c, ft_list.h
Allowed functions : ft_create_elem
Remarks : n/a
22
Chapter XX
Exercice 17 : ft_sorted_list_merge
Exercice : 17
ft_sorted_list_merge
Turn-in directory : ex17/
Files to turn in : ft_sorted_list_merge.c, ft_list.h
Allowed functions : Nothing
Remarks : n/a
23