diff --git a/subjects/btreeapplybylevel.en.md b/subjects/btreeapplybylevel.en.md index e964f86a..37547bb5 100644 --- a/subjects/btreeapplybylevel.en.md +++ b/subjects/btreeapplybylevel.en.md @@ -2,9 +2,7 @@ ### Instructions -Write a function, `BTreeApplyByLevel`, that applies the function given by fn to each node of the tree given by root. - -This function must have the following signature. +Write a function, `BTreeApplyByLevel`, that applies the function given by `fn` to each node of the tree given by `root`. ### Expected function diff --git a/subjects/btreeapplybylevel.fr.md b/subjects/btreeapplybylevel.fr.md index e964f86a..84bb7a32 100644 --- a/subjects/btreeapplybylevel.fr.md +++ b/subjects/btreeapplybylevel.fr.md @@ -2,11 +2,9 @@ ### Instructions -Write a function, `BTreeApplyByLevel`, that applies the function given by fn to each node of the tree given by root. +Écrire une fonction, `BTreeApplyByLevel`, qui applique la fonction donnée par `fn` à chacune des nodes de l'arbre donné par `root`. -This function must have the following signature. - -### Expected function +### Fonction attendue ```go func BTreeApplyByLevel(root *TreeNode, fn interface{}) { @@ -14,9 +12,9 @@ func BTreeApplyByLevel(root *TreeNode, fn interface{}) { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -35,7 +33,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/btreeapplyinorder.en.md b/subjects/btreeapplyinorder.en.md index bfd30ea0..0318f9ab 100644 --- a/subjects/btreeapplyinorder.en.md +++ b/subjects/btreeapplyinorder.en.md @@ -2,8 +2,8 @@ ### Instructions -Write a function that applies a function in order to each element in the tree -(see in order tree walks) +Write a function that applies a function in order to each element in the tree. +(see `in order tree walks`) ### Expected function diff --git a/subjects/btreeapplyinorder.fr.md b/subjects/btreeapplyinorder.fr.md index e182df07..d3741419 100644 --- a/subjects/btreeapplyinorder.fr.md +++ b/subjects/btreeapplyinorder.fr.md @@ -1,11 +1,11 @@ -## btreeinsertdata +## btreeapplyinorder ### Instructions -Write a function that applies a function in order to each element in the tree -(see in order tree walks) +Écrire une fonction qui applique une fonction en ordre (in order) a chaque élément de l'arbre. +(voir les `in order tree walks`) -### Expected function +### Fonction attendue ```go func BTreeApplyInorder(root *TreeNode, f func(...interface{}) (int, error)) { @@ -13,9 +13,9 @@ func BTreeApplyInorder(root *TreeNode, f func(...interface{}) (int, error)) { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -35,7 +35,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build diff --git a/subjects/btreeapplypostorder.en.md b/subjects/btreeapplypostorder.en.md index de6825bc..0a6b7a09 100644 --- a/subjects/btreeapplypostorder.en.md +++ b/subjects/btreeapplypostorder.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function that applies a function using a postorder walk to each element in the tree +Write a function that applies a function using a postorder walk to each element in the tree. ### Expected function diff --git a/subjects/btreeapplypostorder.fr.md b/subjects/btreeapplypostorder.fr.md index e386d350..8d6d596e 100644 --- a/subjects/btreeapplypostorder.fr.md +++ b/subjects/btreeapplypostorder.fr.md @@ -1,10 +1,10 @@ -## btreeinsertdata +## btreeapplypostorder ### Instructions -Write a function that applies a function using a postorder walk to each element in the tree +Écrire une fonction qui applique une fonction en post-ordre (`postorder walk`) à chaque élément de l'arbre. -### Expected function +### Fonction attendue ```go func BTreeApplyPostorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { @@ -12,9 +12,9 @@ func BTreeApplyPostorder(root *piscine.TreeNode, f func(...interface{}) (int, er } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -34,7 +34,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/btreeinsertdata$ go build diff --git a/subjects/btreeapplypreorder.en.md b/subjects/btreeapplypreorder.en.md index 96e68bc3..3fe6b314 100644 --- a/subjects/btreeapplypreorder.en.md +++ b/subjects/btreeapplypreorder.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function that applies a function using a preorder walk to each element in the tree +Write a function that applies a function using a preorder walk to each element in the tree. ### Expected function diff --git a/subjects/btreeapplypreorder.fr.md b/subjects/btreeapplypreorder.fr.md index 4a43b56a..8eba3005 100644 --- a/subjects/btreeapplypreorder.fr.md +++ b/subjects/btreeapplypreorder.fr.md @@ -1,10 +1,10 @@ -## btreeinsertdata +## btreeapplypreorder ### Instructions -Write a function that applies a function using a preorder walk to each element in the tree +Écrire une fonction qui applique une fonction en pré-ordre (`preorder walk`) a chaque élément de l'arbre. -### Expected function +### Fonction attendue ```go func BTreeApplyPreorder(root *TreeNode, f func(...interface{}) (int, error)) { @@ -12,9 +12,9 @@ func BTreeApplyPreorder(root *TreeNode, f func(...interface{}) (int, error)) { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -34,7 +34,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build diff --git a/subjects/btreedeletenode.en.md b/subjects/btreedeletenode.en.md index d308f08b..16fcc39d 100644 --- a/subjects/btreedeletenode.en.md +++ b/subjects/btreedeletenode.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function, `BTreeDeleteNode`, that deletes `node` from the tree given by root. +Write a function, `BTreeDeleteNode`, that deletes `node` from the tree given by `root`. The resulting tree should still follow the binary search tree rules. diff --git a/subjects/btreedeletenode.fr.md b/subjects/btreedeletenode.fr.md index d308f08b..1f0584b3 100644 --- a/subjects/btreedeletenode.fr.md +++ b/subjects/btreedeletenode.fr.md @@ -2,11 +2,11 @@ ### Instructions -Write a function, `BTreeDeleteNode`, that deletes `node` from the tree given by root. +Écrire une fonction, `BTreeDeleteNode`, qui efface `node` d'un arbre donné par `root`. -The resulting tree should still follow the binary search tree rules. +L'arbre en résultant devra toujours suivre les règles des arbres de recherche binaires. -### Expected function +### Fonction attendue ```go func BTreeDeleteNode(root, node *TreeNode) *TreeNode { @@ -15,9 +15,9 @@ func BTreeDeleteNode(root, node *TreeNode) *TreeNode { ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -41,7 +41,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/btreeinsertdata.fr.md b/subjects/btreeinsertdata.fr.md index 2125affc..76899a1c 100644 --- a/subjects/btreeinsertdata.fr.md +++ b/subjects/btreeinsertdata.fr.md @@ -2,11 +2,10 @@ ### Instructions -Write a function that inserts new data in a binary search tree -following the properties of binary search trees. -The nodes must be defined as follows: +Écrire une fonction qui insère de la nouvelle data dans un arbre binaire en suivant les propriétés des arbres de recherche binaires. +Les nodes doivent être définies comme ci-dessous: -### Expected function +### Fonction attendue ```go type TreeNode struct { @@ -19,9 +18,9 @@ func BTreeInsertData(root *TreeNode, data string) *TreeNode { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -44,7 +43,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/btreeinsertdata$ go build diff --git a/subjects/btreeisbinary.en.md b/subjects/btreeisbinary.en.md index 578f7c3f..40ec314b 100644 --- a/subjects/btreeisbinary.en.md +++ b/subjects/btreeisbinary.en.md @@ -2,9 +2,7 @@ ### Instructions -Write a function, `BTreeIsBinary`, that returns true only if the tree given by root follows the binary search tree properties. - -This function must have the following signature. +Write a function, `BTreeIsBinary`, that returns `true` only if the tree given by `root` follows the binary search tree properties. ### Expected function diff --git a/subjects/btreeisbinary.fr.md b/subjects/btreeisbinary.fr.md index 2a93d314..663231f7 100644 --- a/subjects/btreeisbinary.fr.md +++ b/subjects/btreeisbinary.fr.md @@ -2,11 +2,9 @@ ### Instructions -Write a function, BTreeIsBinary, that returns true only if the tree given by root follows the binary search tree properties. +Écrire une fonction, `BTreeIsBinary`, qui retourne `true` seulement si l'arbre donné par `root` suit les propriétés des arbres de recherche binaires. -This function must have the following signature. - -### Expected function +### Fonction attendue ```go func BTreeIsBinary(root *TreeNode) bool { @@ -14,9 +12,9 @@ func BTreeIsBinary(root *TreeNode) bool { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -35,7 +33,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/btreelevelcount.en.md b/subjects/btreelevelcount.en.md index 14a097e5..b93dd20e 100644 --- a/subjects/btreelevelcount.en.md +++ b/subjects/btreelevelcount.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function, `BTreeLevelCount`, that return the number of levels of the tree (height of the tree) +Write a function, `BTreeLevelCount`, that returns the number of levels of the binary tree (height of the tree) ### Expected function diff --git a/subjects/btreelevelcount.fr.md b/subjects/btreelevelcount.fr.md index ef9c7806..dfd4fd91 100644 --- a/subjects/btreelevelcount.fr.md +++ b/subjects/btreelevelcount.fr.md @@ -2,9 +2,9 @@ ### Instructions -Write a function, BTreeLevelCount, that return the number of levels of the tree (height of the tree) +Écrire une fonction, `BTreeLevelCount`, qui retourne le nombre de niveaux de l'arbre binaire. (la hauteur de l'arbre) -### Expected function +### Fonction attendue ```go func BTreeLevelCount(root *TreeNode) int { @@ -12,9 +12,9 @@ func BTreeLevelCount(root *TreeNode) int { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -34,7 +34,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/btreemax.en.md b/subjects/btreemax.en.md index 3fa2bc5c..65aa35d7 100644 --- a/subjects/btreemax.en.md +++ b/subjects/btreemax.en.md @@ -2,9 +2,7 @@ ### Instructions -Write a function, `BTreeMax`, that returns the node with the maximum value in the tree given by root - -This function must have the following signature. +Write a function, `BTreeMax`, that returns the node with the maximum value in the tree given by `root`. ### Expected function diff --git a/subjects/btreemax.fr.md b/subjects/btreemax.fr.md index 3fa2bc5c..79b0255f 100644 --- a/subjects/btreemax.fr.md +++ b/subjects/btreemax.fr.md @@ -2,11 +2,9 @@ ### Instructions -Write a function, `BTreeMax`, that returns the node with the maximum value in the tree given by root +Écrire une fonction, `BTreeMax`, qui retourne la node avec la valeur maximum de l'arbre donné par `root`. -This function must have the following signature. - -### Expected function +### Fonction attendue ```go func BTreeMax(root *TreeNode) *TreeNode { @@ -14,9 +12,9 @@ func BTreeMax(root *TreeNode) *TreeNode { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -37,7 +35,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/btreemin.en.md b/subjects/btreemin.en.md index 8de2f9a0..0de3352e 100644 --- a/subjects/btreemin.en.md +++ b/subjects/btreemin.en.md @@ -4,8 +4,6 @@ Write a function, `BTreeMin`, that returns the node with the minimum value in the tree given by root -This function must have the following signature. - ### Expected function ```go diff --git a/subjects/btreemin.fr.md b/subjects/btreemin.fr.md index 8de2f9a0..79c865d1 100644 --- a/subjects/btreemin.fr.md +++ b/subjects/btreemin.fr.md @@ -2,11 +2,9 @@ ### Instructions -Write a function, `BTreeMin`, that returns the node with the minimum value in the tree given by root +Écrire une fonction, `BTreeMin`, qui retourne la node avec la valeur minimum de l'arbre donné par `root`. -This function must have the following signature. - -### Expected function +### Fonction attendue ```go func BTreeMin(root *TreeNode) *TreeNode { @@ -14,9 +12,9 @@ func BTreeMin(root *TreeNode) *TreeNode { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -37,7 +35,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/btreeprintroot.en.md b/subjects/btreeprintroot.en.md index 433578ac..68c31170 100644 --- a/subjects/btreeprintroot.en.md +++ b/subjects/btreeprintroot.en.md @@ -1,9 +1,8 @@ -## printroot +## btreeprintroot ### Instructions Write a function to print the value of the root node of a binary tree. -You have to create a new number and print the value of data The nodes must be defined as follows: ### Expected function diff --git a/subjects/btreeprintroot.fr.md b/subjects/btreeprintroot.fr.md index 433578ac..4b6da978 100644 --- a/subjects/btreeprintroot.fr.md +++ b/subjects/btreeprintroot.fr.md @@ -1,12 +1,11 @@ -## printroot +## btreeprintroot ### Instructions -Write a function to print the value of the root node of a binary tree. -You have to create a new number and print the value of data -The nodes must be defined as follows: +Écrire une fonction qui affiche la valeur de node `root` d'un arbre binaire. +Les nodes doivent être définies comme ci-dessous: -### Expected function +### Fonction attendue ```go type TreeNode struct { @@ -19,9 +18,9 @@ func PrintRoot(root *TreeNode){ } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -36,7 +35,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/printroot$ go build diff --git a/subjects/btreesearchitem.en.md b/subjects/btreesearchitem.en.md index 6cfa461d..cc8c4105 100644 --- a/subjects/btreesearchitem.en.md +++ b/subjects/btreesearchitem.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function that searches for an item with a data element equal to elem and return that node +Write a function that searches for a node with a data element equal to `elem`and that returns that node. ### Expected function diff --git a/subjects/btreesearchitem.fr.md b/subjects/btreesearchitem.fr.md index 2367eead..bf5cf598 100644 --- a/subjects/btreesearchitem.fr.md +++ b/subjects/btreesearchitem.fr.md @@ -1,10 +1,10 @@ -## btreeinsertdata +## btreesearchitem ### Instructions -Write a function that searches for an item with a data element equal to elem and return that node +Écrire une fonction qui cherche une node avec un élément de data égal à `elem` et qui retourne cette node. -### Expected function +### Fonction attendue ```go func BTreeSearchItem(root *TreeNode, elem string) *TreeNode { @@ -12,9 +12,9 @@ func BTreeSearchItem(root *TreeNode, elem string) *TreeNode { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -60,7 +60,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build diff --git a/subjects/btreetransplant.en.md b/subjects/btreetransplant.en.md index dd4ed4fa..5aa9b841 100644 --- a/subjects/btreetransplant.en.md +++ b/subjects/btreetransplant.en.md @@ -2,10 +2,7 @@ ### Instructions - -In order to move subtrees around within the binary search tree, write a function, `BTreeTransplant`, which replaces the subtree started by `node` with the node called `rplc` in the tree given by `root`. - -This function must have the following signature. +In order to move subtrees around within the binary search tree, write a function, `BTreeTransplant`, which replaces the subtree started by `node` with the node `rplc` in the tree given by `root`. ### Expected function diff --git a/subjects/btreetransplant.fr.md b/subjects/btreetransplant.fr.md index 50beed3a..d45f281f 100644 --- a/subjects/btreetransplant.fr.md +++ b/subjects/btreetransplant.fr.md @@ -2,11 +2,9 @@ ### Instructions -In order to move subtrees around within the binary search tree, write a function, `BTreeTransplant`, which replaces the subtree started by `node` with the node called `rplc` in the tree given by `root`. +Afin de déplacer les sous-arbres dans l'arbre de recherche binaire, écrire une fonction, `BTreeTransplant`, qui remplace le sous-arbre commencé par `node` avec la node `rplc` dans l'arbre donné par `root`. -This function must have the following signature. - -### Expected function +### Fonction attendue ```go func BTreeTransplant(root, node, rplc *TreeNode) *TreeNode { @@ -14,9 +12,9 @@ func BTreeTransplant(root, node, rplc *TreeNode) *TreeNode { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -38,7 +36,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/student/test$ go build diff --git a/subjects/findnextprime.en.md b/subjects/findnextprime.en.md index 5743622f..4e74607f 100644 --- a/subjects/findnextprime.en.md +++ b/subjects/findnextprime.en.md @@ -4,6 +4,8 @@ Write a function that returns the first prime number that is equal or superior to the `int` passed as parameter. +The function must be optimized in order to avoid time-outs with the tester. + ### Expected function ```go diff --git a/subjects/findnextprime.fr.md b/subjects/findnextprime.fr.md index c1761842..5af76ba6 100644 --- a/subjects/findnextprime.fr.md +++ b/subjects/findnextprime.fr.md @@ -4,6 +4,8 @@ Écrire une fonction qui renvoie le premier nombre premier qui est égal ou supérieur à l'`int` passé en paramètre. +La fonction devra être optimisée pour éviter les time-outs avec le testeur. + ### Fonction attendue ```go diff --git a/subjects/isprime.en.md b/subjects/isprime.en.md index b5a2f91f..8dc2593b 100644 --- a/subjects/isprime.en.md +++ b/subjects/isprime.en.md @@ -4,6 +4,8 @@ Write a function that returns `true` if the `int` passed as parameter is a prime number. Otherwise it returns `false`. +The function must be optimized in order to avoid time-outs with the tester. + ### Expected function ```go diff --git a/subjects/isprime.fr.md b/subjects/isprime.fr.md index be345292..b244d29a 100644 --- a/subjects/isprime.fr.md +++ b/subjects/isprime.fr.md @@ -4,6 +4,8 @@ Écrire une fonction qui renvoie `true` si l'`int` passé en paramètre est un nombre premier. Autrement elle renvoie `false`. +La fonction devra être optimisée pour éviter les time-outs avec le testeur. + ### Fonction attendue ```go diff --git a/subjects/listat.en.md b/subjects/listat.en.md index 3a6a650a..0ae01759 100644 --- a/subjects/listat.en.md +++ b/subjects/listat.en.md @@ -1,10 +1,10 @@ -## listpushback +## listat ### Instructions -Write a function `ListAt` that takes one pointer to the list, `l`, and an `int` as parameters. This function should print a `NodeL` in the position `pos` in the linked list. +Write a function `ListAt` that takes a pointer to the list `l` and an `int pos` as parameters. This function should print the `NodeL` in the position `pos` of the linked list `l`. -- In case of error it should print `nil` +- In case of error the fonction should print `nil`. ### Expected function and structure @@ -56,4 +56,4 @@ student@ubuntu:~/piscine/test$ ./test how are student@ubuntu:~/piscine/test$ -``` \ No newline at end of file +``` diff --git a/subjects/listat.fr.md b/subjects/listat.fr.md index 7db913a6..9d7467dd 100644 --- a/subjects/listat.fr.md +++ b/subjects/listat.fr.md @@ -1,13 +1,22 @@ -## countif +## listat ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListAt` qui prend un pointeur sur la liste `l` et un `int pos` comme paramètres. Cette fonction devra afficher la `NodeL` à la position `pos` de la liste chaînée `l`. -### Fonction attendue +- En cas d'erreur la fonction affichera `nil`. + +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + + +func ListAt(l *NodeL, pos int) *NodeL{ + } ``` @@ -24,13 +33,18 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + + piscine.ListPushBack(link, "hello") + piscine.ListPushBack(link, "how are") + piscine.ListPushBack(link, "you") + piscine.ListPushBack(link, 1) + + fmt.Println(piscine.ListAt(link.Head, 3).Data) + fmt.Println(piscine.ListAt(link.Head, 1).Data) + fmt.Println(piscine.ListAt(link.Head, 7)) } + ``` Et son résultat : @@ -38,7 +52,8 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +1 +how are + student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listclear.en.md b/subjects/listclear.en.md index 537abebc..590f436d 100644 --- a/subjects/listclear.en.md +++ b/subjects/listclear.en.md @@ -1,10 +1,10 @@ -## listpushback +## listclear ### Instructions -Write a function `ListClear` that deletes all `nodes` from a linked list, deleting the link between the list. +Write a function `ListClear` that deletes all `nodes` from a linked list `l`. -- Tip: assign the list's pointer to nil +- Tip: assign the list's pointer to `nil`. ### Expected function and structure @@ -55,7 +55,6 @@ func main() { ``` - And its output : ```console diff --git a/subjects/listclear.fr.md b/subjects/listclear.fr.md index 7db913a6..fa073f9b 100644 --- a/subjects/listclear.fr.md +++ b/subjects/listclear.fr.md @@ -1,13 +1,15 @@ -## countif +## listclear ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListClear` qui efface toutes les `nodes` d'une liste chaînée `l`. -### Fonction attendue +- Indice: assigner le pointeur de la liste à `nil`. + +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +func ListClear(l *List) { } ``` @@ -20,17 +22,37 @@ package main import ( "fmt" + piscine ".." ) +type List = piscine.List +type Node = piscine.NodeL + +func PrintList(l *List) { + link := l.Head + for link != nil { + fmt.Print(link.Data, " -> ") + link = link.Next + } + fmt.Println(nil) +} + func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &List{} + + piscine.ListPushBack(link, "I") + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, "something") + piscine.ListPushBack(link, 2) + + fmt.Println("------list------") + PrintList(link) + piscine.ListClear(link) + fmt.Println("------updated list------") + PrintList(link) } + ``` Et son résultat : @@ -38,7 +60,9 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +------list------ +I -> 1 -> something -> 2 -> +------updated list------ + student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listfind.en.md b/subjects/listfind.en.md index 24f59ce8..b17e4f45 100644 --- a/subjects/listfind.en.md +++ b/subjects/listfind.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `ListFind` that returns the address of the first node in the list that is determined to be equal to `ref` by the functions `CompStr`. +Write a function `ListFind` that returns the address of the first node in the list `l` that is determined to be equal to `ref` by the function `CompStr`. -- For this you shoud use the function `CompStr`. +- For this exercise the function `CompStr` must be used. ### Expected function and structure @@ -64,6 +64,7 @@ student@ubuntu:~/piscine/test$ ./test hello2 student@ubuntu:~/piscine/test$ ``` + ### Note -- The address may be different in each execution of the program. \ No newline at end of file +- The address may be different in each execution of the program. diff --git a/subjects/listfind.fr.md b/subjects/listfind.fr.md index 7db913a6..6f553abf 100644 --- a/subjects/listfind.fr.md +++ b/subjects/listfind.fr.md @@ -1,13 +1,30 @@ -## countif +## listfind ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListFind` qui retourne l'adresse de la première node dans la liste `l` qui est déterminée comme étant égale à `ref` par la fonction `CompStr`. -### Fonction attendue +- Pour cet exercice la fonction `CompStr` doit être utilisée. + +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func CompStr(a, b interface{}) bool { + return a == b +} + +func ListFind(l *List, ref interface{}, comp func(a, b interface{}) bool) *interface{} { + } ``` @@ -24,12 +41,17 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + + piscine.ListPushBack(link, "hello") + piscine.ListPushBack(link, "hello1") + piscine.ListPushBack(link, "hello2") + piscine.ListPushBack(link, "hello3") + + found := piscine.ListFind(link, interface{}("hello2"), piscine.CompStr) + + fmt.Println(found) + fmt.Println(*found) } ``` @@ -38,7 +60,11 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +0xc42000a0a0 +hello2 student@ubuntu:~/piscine/test$ ``` + +### Note + +- L'addresse peut être différente à chaque exécution du programme. diff --git a/subjects/listforeach.en.md b/subjects/listforeach.en.md index 76359adb..d2f91bb4 100644 --- a/subjects/listforeach.en.md +++ b/subjects/listforeach.en.md @@ -1,12 +1,12 @@ -## listpushback +## listforeach ### Instructions -Write a function `ListForEach` that applies a function given as argument to the information within each of the list's links. +Write a function `ListForEach` that applies a function given as argument to the data within each node of the list `l`. - The function given as argument must have a pointer as argument: `l *List` -- Copy the functions `Add2_node` and `Subtract3_node` in the same file you defined the function `ListForEach`. +- Copy the functions `Add2_node` and `Subtract3_node` in the same file as the function `ListForEach` is defined. ### Expected function and structure diff --git a/subjects/listforeach.fr.md b/subjects/listforeach.fr.md index 7db913a6..75d6c2e5 100644 --- a/subjects/listforeach.fr.md +++ b/subjects/listforeach.fr.md @@ -1,13 +1,45 @@ -## countif +## listforeach ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListForEach` qui applique un fonction donnée en argument à la data contenue dans chacune des nodes d'une liste `l`. -### Fonction attendue +- La fonction donnée en argument doit avoir un pointeur comme argument: `l *List` + +- Copier les fonctions `Add2_node` et `Subtract3_node` dans le même fichier où la fonction `ListForEach` est définie. + +### Fonction et struture attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListForEach(l *List, f func(*NodeL)) { +} + +func Add2_node(node *NodeL) { + switch node.Data.(type) { + case int: + node.Data = node.Data.(int) + 2 + case string: + node.Data = node.Data.(string) + "2" + } +} + +func Subtract3_node(node *NodeL) { + switch node.Data.(type) { + case int: + node.Data = node.Data.(int) - 3 + case string: + node.Data = node.Data.(string) + "-3" + } } ``` @@ -24,12 +56,20 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + + piscine.ListPushBack(link, "1") + piscine.ListPushBack(link, "2") + piscine.ListPushBack(link, "3") + piscine.ListPushBack(link, "5") + + piscine.ListForEach(link, piscine.Add2) + + it := link.Head + for it != nil { + fmt.Println(it.Data) + it = it.Next + } } ``` @@ -38,7 +78,9 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +12 +22 +32 +52 student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listforeachif.en.md b/subjects/listforeachif.en.md index 40cd1ccb..497e3dc2 100644 --- a/subjects/listforeachif.en.md +++ b/subjects/listforeachif.en.md @@ -2,15 +2,15 @@ ### Instructions -Write a function `ListForEachIf` that applies a function given as argument to the information within some nodes of the list. +Write a function `ListForEachIf` that applies a function given as argument to the data within some of the nodes of the list `l`. -- This functions receives two functions: +- This function receives two functions: - - `f` is a functions that is applied to the node. + - `f` is a function that is applied to the node. - - `cond` is a predicate (a function that returns true or false) and will be use to determine if the function `f` would be applied to the node. + - `cond` is a function that returns a `boolean` and it will be used to determine if the function `f` should be applied to the node. -- The function given as argument must have a pointer as argument: `*NodeL`. +- The function given as argument must have a pointer `*NodeL` as argument. ### Expected function and structure diff --git a/subjects/listforeachif.fr.md b/subjects/listforeachif.fr.md index 7db913a6..c0f6be18 100644 --- a/subjects/listforeachif.fr.md +++ b/subjects/listforeachif.fr.md @@ -1,13 +1,62 @@ -## countif +## listforeachif ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListForEachIf` qui applique un fonction donnée en argument à la data contenue dans certaines des nodes d'une liste `l`. -### Fonction attendue +- Cette fonction reçoit deux fonctions: + + - `f` est la fonction qui est appliqué à la node. + + - `cond` est une fonction qui retourne un `boolean` et qui sera utilisée pour déterminer si la fonction`f` doit être appliquée à la node. + +- La fonction donnée en argument doit avoir un pointeur `*NodeL` comme argument. + +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func IsPositive_node(node *NodeL) bool { + switch node.Data.(type) { + case int, float32, float64, byte: + return node.Data.(int) > 0 + case string, rune: + return false + } + return false +} + +func IsNegative_node(node *NodeL) bool { + switch node.Data.(type) { + case int, float32, float64, byte: + return node.Data.(int) > 0 + case string, rune: + return false + } + return false +} + +func IsNotNumeric_node(node *NodeL) bool { + switch node.Data.(type) { + case int, float32, float64, byte: + return false + case string, rune: + return true + } + return true +} + +func ListForEachIf(l *List, f func(*NodeL), cond func(*NodeL) bool) { + } ``` @@ -19,17 +68,50 @@ Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : package main import ( - "fmt" piscine ".." + "fmt" ) +func PrintElem(node *piscine.NodeL) { + fmt.Println(node.Data) +} + +func StringToInt(node *piscine.NodeL) { + node.Data = 2 +} + +func PrintList(l *piscine.List) { + it := l.Head + for it != nil { + fmt.Print(it.Data, "->") + it = it.Next + } + fmt.Println() +} + func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, "hello") + piscine.ListPushBack(link, 3) + piscine.ListPushBack(link, "there") + piscine.ListPushBack(link, 23) + piscine.ListPushBack(link, "!") + piscine.ListPushBack(link, 54) + + PrintList(link) + + fmt.Println() + fmt.Println("--------function applied--------") + piscine.ListForEachIf(link, PrintElem, piscine.IsPositive_node) + + piscine.ListForEachIf(link, StringToInt, piscine.IsNotNumeric_node) + + fmt.Println("--------function applied--------") + PrintList(link) + + fmt.Println() } ``` @@ -38,7 +120,12 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +1 -> hello -> 3 -> there -> 23 -> ! -> 54 -> +--------function applied-------- +hello +there +! +--------function applied-------- +1 -> 1 -> 3 -> 1 -> 23 -> 1 -> 54 -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listlast.en.md b/subjects/listlast.en.md index e46d0aa8..4fa672ad 100644 --- a/subjects/listlast.en.md +++ b/subjects/listlast.en.md @@ -1,8 +1,8 @@ -## listpushback +## listlast ### Instructions -Write a function `ListLast` that returns the last element of the linked list. +Write a function `ListLast` that returns the last element of a linked list `l`. ### Expected function and structure diff --git a/subjects/listlast.fr.md b/subjects/listlast.fr.md index e46d0aa8..d50831d1 100644 --- a/subjects/listlast.fr.md +++ b/subjects/listlast.fr.md @@ -1,10 +1,10 @@ -## listpushback +## listlast ### Instructions -Write a function `ListLast` that returns the last element of the linked list. +Écrire une fonction `ListLast` qui retourne le dernier élément d'une liste chaînée `l`. -### Expected function and structure +### Fonction et structure attendue ```go type Node struct { @@ -21,9 +21,9 @@ func ListLast(l *List) interface{} { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -48,7 +48,7 @@ func main() { ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build diff --git a/subjects/listmerge.en.md b/subjects/listmerge.en.md index db7b4c8b..0a72201f 100644 --- a/subjects/listmerge.en.md +++ b/subjects/listmerge.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `ListMerge` that places elements of a list `l2` at the end of an other list `l1`. +Write a function `ListMerge` that places elements of a list `l2` at the end of another list `l1`. -- You can't create new elements! +- New elements should not be created! ### Expected function and structure diff --git a/subjects/listmerge.fr.md b/subjects/listmerge.fr.md index 7db913a6..acf7cce6 100644 --- a/subjects/listmerge.fr.md +++ b/subjects/listmerge.fr.md @@ -1,13 +1,26 @@ -## countif +## listmerge ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListMerge` qui place les éléments d'une liste `l2` à la fin d'une autre liste `l1`. -### Fonction attendue +- Des nouveaux éléments ne doivent pas être créés! + +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListMerge(l1 *List, l2 *List) { + } ``` @@ -20,16 +33,40 @@ package main import ( "fmt" + piscine ".." ) +func PrintList(l *piscine.List) { + it := l.Head + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next + } + fmt.Print(nil, "\n") +} + func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + link2 := &piscine.List{} + + piscine.ListPushBack(link, "a") + piscine.ListPushBack(link, "b") + piscine.ListPushBack(link, "c") + piscine.ListPushBack(link, "d") + fmt.Println("-----first List------") + PrintList(link) + + piscine.ListPushBack(link2, "e") + piscine.ListPushBack(link2, "f") + piscine.ListPushBack(link2, "g") + piscine.ListPushBack(link2, "h") + fmt.Println("-----second List------") + PrintList(link2) + + fmt.Println("-----Merged List-----") + piscine.ListMerge(link, link2) + PrintList(link) } ``` @@ -38,7 +75,6 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +a -> b -> c -> d -> e -> f -> g -> h -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listpushback.en.md b/subjects/listpushback.en.md index 45fa4d64..9cecd849 100644 --- a/subjects/listpushback.en.md +++ b/subjects/listpushback.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function `ListPushBack` that inserts a new element `NodeL` at the end of the list, using the structure `List` +Write a function `ListPushBack` that inserts a new element `NodeL` at the end of the list `l` while using the structure `List`. ### Expected function and structure diff --git a/subjects/listpushback.fr.md b/subjects/listpushback.fr.md index 7db913a6..e4637db8 100644 --- a/subjects/listpushback.fr.md +++ b/subjects/listpushback.fr.md @@ -1,13 +1,23 @@ -## countif +## listpushback ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListPushBack` qui insère un nouvel élément `NodeL` à la fin de la liste `l` en utilisant la structure `List`. -### Fonction attendue +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListPushBack(l *List, data interface{}) { } ``` @@ -24,12 +34,17 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + + link := &piscine.List{} + + piscine.ListPushBack(link, "Hello") + piscine.ListPushBack(link, "man") + piscine.ListPushBack(link, "how are you") + + for link.Head != nil { + fmt.Println(link.Head.Data) + link.Head = link.Head.Next + } } ``` @@ -38,7 +53,8 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +Hello +man +how are you student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listpushfront.en.md b/subjects/listpushfront.en.md index 35901b23..dd01e9fa 100644 --- a/subjects/listpushfront.en.md +++ b/subjects/listpushfront.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function `ListPushBack` that inserts a new element `node` at the beginning of the list using `list` +Write a function `ListPushBack` that inserts a new element `NodeL` at the beginning of the list `l` while using the structure `List` ### Expected function and structure diff --git a/subjects/listpushfront.fr.md b/subjects/listpushfront.fr.md index 7db913a6..4a2ddd2a 100644 --- a/subjects/listpushfront.fr.md +++ b/subjects/listpushfront.fr.md @@ -1,13 +1,23 @@ -## countif +## listpushback ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListPushBack` qui insère un nouvel élément `NodeL` au début de la liste `l` en utilisant la structure `List`. -### Fonction attendue +### Fonction et structue attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListPushFront(l *List, data interface{}) { } ``` @@ -19,17 +29,23 @@ Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : package main import ( - "fmt" piscine ".." + "fmt" ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + + link := &piscine.List{} + + piscine.ListPushFront(link, "Hello") + piscine.ListPushFront(link, "man") + piscine.ListPushFront(link, "how are you") + + it := link.Head + for it != nil { + fmt.Println(it.Data) + it = it.Next + } } ``` @@ -38,7 +54,8 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +how are you +man +Hello student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listremoveif.fr.md b/subjects/listremoveif.fr.md index 7db913a6..fa4c9650 100644 --- a/subjects/listremoveif.fr.md +++ b/subjects/listremoveif.fr.md @@ -1,13 +1,24 @@ -## countif +## listremoveif ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListRemoveIf` qui supprime tous les éléments qui sont égaux à la `data_ref` introduite dans l'argument de la fonction. -### Fonction attendue +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListRemoveIf(l *List, data_ref interface{}) { + } ``` @@ -20,17 +31,51 @@ package main import ( "fmt" + piscine ".." ) +func PrintList(l *piscine.List) { + it := l.Head + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next + } + + fmt.Print(nil, "\n") +} + func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + link2 := &piscine.List{} + + fmt.Println("----normal state----") + piscine.ListPushBack(link2, 1) + PrintList(link2) + piscine.ListRemoveIf(link2, 1) + fmt.Println("------answer-----") + PrintList(link2) + fmt.Println() + + fmt.Println("----normal state----") + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, "Hello") + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, "There") + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, "How") + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, "are") + piscine.ListPushBack(link, "you") + piscine.ListPushBack(link, 1) + PrintList(link) + + piscine.ListRemoveIf(link, 1) + fmt.Println("------answer-----") + PrintList(link) } + ``` Et son résultat : @@ -38,7 +83,14 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +----normal state---- +1 -> +------answer----- + + +----normal state---- +1 -> Hello -> 1 -> There -> 1 -> 1 -> How -> 1 -> are -> you -> 1 -> +------answer----- +Hello -> There -> How -> are -> you -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listreverse.en.md b/subjects/listreverse.en.md index f661ef47..ceffdc40 100644 --- a/subjects/listreverse.en.md +++ b/subjects/listreverse.en.md @@ -1,10 +1,8 @@ -## listpushback +## listreverse ### Instructions -Write a function `ListReverse` that reverses the elements order of a given linked list. - -- Use pointers when ever you can +Write a function `ListReverse` that reverses the order of the elements of a given linked list `l`. ### Expected function and structure @@ -69,4 +67,4 @@ student@ubuntu:~/piscine/test$ ./test Tail &{1 } Head &{4 0xc42000a140} student@ubuntu:~/piscine/test$ -``` \ No newline at end of file +``` diff --git a/subjects/listreverse.fr.md b/subjects/listreverse.fr.md index 7db913a6..ec962b58 100644 --- a/subjects/listreverse.fr.md +++ b/subjects/listreverse.fr.md @@ -1,13 +1,23 @@ -## countif +## listreverse ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListReverse` qui inverse l'ordre des éléments d'une liste chaînée `l` donnée. -### Fonction attendue +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListReverse(l *List) { } ``` @@ -24,12 +34,24 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, 2) + piscine.ListPushBack(link, 3) + piscine.ListPushBack(link, 4) + + piscine.ListReverse(link) + + it := link.Head + + for it != nil { + fmt.Println(it.Data) + it = it.Next + } + + fmt.Println("Tail", link.Tail) + fmt.Println("Head", link.Head) } ``` @@ -38,7 +60,11 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 +4 +3 2 +1 +Tail &{1 } +Head &{4 0xc42000a140} student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listsize.en.md b/subjects/listsize.en.md index da623774..eea17c08 100644 --- a/subjects/listsize.en.md +++ b/subjects/listsize.en.md @@ -1,8 +1,8 @@ -## listpushback +## listsize ### Instructions -Write a function `ListSize` that returns the number of elements in the list. +Write a function `ListSize` that returns the number of elements in a linked list `l`. ### Expected function and structure diff --git a/subjects/listsize.fr.md b/subjects/listsize.fr.md index 7db913a6..77a05791 100644 --- a/subjects/listsize.fr.md +++ b/subjects/listsize.fr.md @@ -1,13 +1,24 @@ -## countif +## listsize ### Instructions -Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. +Écrire une fonction `ListSize` qui retourne le nombre d'éléments dans une liste chaînée `l`. -### Fonction attendue +### Fonction et structure attendues ```go -func CountIf(f func(string) bool, tab []string) int { +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL +} + +func ListSize(l *List) int { + } ``` @@ -24,13 +35,16 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This","1", "is", "4", "you"} - answer1 := piscine.CountIf(piscine.IsNumeric, tab1) - answer2 := piscine.CountIf(piscine.IsNumeric, tab2) - fmt.Println(answer1) - fmt.Println(answer2) + link := &piscine.List{} + + piscine.ListPushFront(link, "Hello") + piscine.ListPushFront(link, "2") + piscine.ListPushFront(link, "you") + piscine.ListPushFront(link, "man") + + fmt.Println(piscine.ListSize(link)) } + ``` Et son résultat : @@ -38,7 +52,6 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +4 student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listsort.en.md b/subjects/listsort.en.md index a9e5b8bf..5a3393b3 100644 --- a/subjects/listsort.en.md +++ b/subjects/listsort.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `ListSort` that sorts the linked list by ascending order. +Write a function `ListSort` that sorts the nodes of a linked list by ascending order. -- This time you only will have the `node` structure. +- The `NodeI` structure will be the only one used. ### Expected function and structure diff --git a/subjects/listsort.fr.md b/subjects/listsort.fr.md index c146d367..a87bdc0e 100644 --- a/subjects/listsort.fr.md +++ b/subjects/listsort.fr.md @@ -1,16 +1,12 @@ -## listpushback +## listsort ### Instructions -Write a function `ListSort` that sorts the linked list by ascending order. +Écrire une fonction `ListSort` qui trie les nodes d'une liste chaînée par ordre croissant. -- This time you only will have the `node` structure. +- La structure `NodeI` sera la seule utilisée. -- Try to use recursive. - -- Use pointers when ever you can. - -### Expected function and structure +### Fonction et structure attendues ```go type NodeI struct { @@ -23,9 +19,9 @@ func ListSort(l *NodeI) *NodeI { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -37,13 +33,12 @@ import ( ) func PrintList(l *piscine.NodeI) { - m := l - for m != nil { - fmt.Print(m.Data, " -> ") - m = m.Next + it := l + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next } - fmt.Print(nil) - fmt.Println() + fmt.Print(nil, "\n") } func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { @@ -73,7 +68,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index 227b06a0..d4721ae5 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `SortedListMerge` that merges two lists, `n1` and `n2`, but it has to join them in ascending order. +Write a function `SortedListMerge` that merges two lists `n1` and `n2` in ascending order. -- Assume that `n1` and `n2` are already sorted +- During the tests `n1` and `n2` will already be initially sorted. ### Expected function and structure diff --git a/subjects/sortedlistmerge.fr.md b/subjects/sortedlistmerge.fr.md index db9a3b10..d2aa50d5 100644 --- a/subjects/sortedlistmerge.fr.md +++ b/subjects/sortedlistmerge.fr.md @@ -2,13 +2,11 @@ ### Instructions -Write a function `SortedListMerge` that mereges two lists, `n1` and `n2`, but it as to join them in ascending order. +Écrire une fonction `SortedListMerge` qui merge deux listes `n1` et `n2` en ordre ascendant. -- Tip each list as to be already sorted. +- Pendant les tests `n1` et `n2` seront déjà triées. -- Use pointers when ever you can. - -### Expected function and structure +### Fonction et structure attendues ```go func SortedListMerge(n1 *NodeI, n2 *NodeI) *NodeI { @@ -16,9 +14,9 @@ func SortedListMerge(n1 *NodeI, n2 *NodeI) *NodeI { } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -29,17 +27,13 @@ import ( piscine ".." ) -type node = piscine.NodeI -type nodes = piscine.NodeI - func PrintList(l *piscine.NodeI) { - m := l - for m != nil { - fmt.Print(m.Data, " -> ") - m = m.Next + it := l + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next } - fmt.Print(nil) - fmt.Println() + fmt.Print(nil, "\n") } func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { @@ -57,26 +51,25 @@ func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { } func main() { - var link *node - var link2 *nodes + var link *piscine.NodeI + var link2 *piscine.NodeI - link = listPushBack(link, 5) link = listPushBack(link, 3) + link = listPushBack(link, 5) link = listPushBack(link, 7) link2 = listPushBack(link2, -2) - link2 = listPushBack(link2, 4) + link2 = listPushBack(link2, 9) PrintList(piscine.SortedListMerge(link2, link)) } - ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test --2 -> 3 -> 4 -> 5 -> 7 -> +-2 -> 3 -> 5 -> 7 -> 9 -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/sortlistinsert.en.md b/subjects/sortlistinsert.en.md index aff98a7b..5b24a6d6 100644 --- a/subjects/sortlistinsert.en.md +++ b/subjects/sortlistinsert.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `SortListInsert` that inserts `data_ref` in the linked list, but keeping the list sorted in ascending order. +Write a function `SortListInsert` that inserts `data_ref` in the linked list `l` while keeping the list sorted in ascending order. -- You can assume that the list passed as an argument is already sorted. +- During the tests the list passed as an argument will be already sorted. ### Expected function and structure diff --git a/subjects/sortlistinsert.fr.md b/subjects/sortlistinsert.fr.md index 285ea95d..3d6da413 100644 --- a/subjects/sortlistinsert.fr.md +++ b/subjects/sortlistinsert.fr.md @@ -2,13 +2,12 @@ ### Instructions -Write a function `SortListInsert` that inserts `data_ref` in the linked list, but it as to remain sorted in ascending order. +Écrire une fonction `SortListInsert` qui insère `data_ref` dans la liste chaînée `l` +tout en gardant cette liste triée par ordre croissant. -- The list as to be alredy sorted. +- Pendant les tests la liste passée en argument sera déjà triée. -- Use pointers when ever you can. - -### Expected function and structure +### Fonction et structure attendues ```go func SortListInsert(l *NodeI, data_ref int) *NodeI{ @@ -16,9 +15,9 @@ func SortListInsert(l *NodeI, data_ref int) *NodeI{ } ``` -### Usage +### Utilisation -Here is a possible [program](TODO-LINK) to test your function : +Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : ```go package main @@ -30,13 +29,12 @@ import ( ) func PrintList(l *piscine.NodeI) { - m := l - for m != nil { - fmt.Print(m.Data, " -> ") - m = m.Next + it := l + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next } - fmt.Print(nil) - fmt.Println() + fmt.Print(nil, "\n") } func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { @@ -69,7 +67,7 @@ func main() { } ``` -And its output : +Et son résultat : ```console student@ubuntu:~/piscine/test$ go build