Browse Source

Quest11and12 translations (#252)

* translations of quest11 linked lists

* translations quest 11 and 12, and correction of isprime and find nextprime readmes

* Corrected spelling mistakes.
content-update
Christopher Fremond 5 years ago committed by MarieMalarme
parent
commit
f798b2cc93
  1. 4
      subjects/btreeapplybylevel.en.md
  2. 12
      subjects/btreeapplybylevel.fr.md
  3. 4
      subjects/btreeapplyinorder.en.md
  4. 14
      subjects/btreeapplyinorder.fr.md
  5. 2
      subjects/btreeapplypostorder.en.md
  6. 12
      subjects/btreeapplypostorder.fr.md
  7. 2
      subjects/btreeapplypreorder.en.md
  8. 12
      subjects/btreeapplypreorder.fr.md
  9. 2
      subjects/btreedeletenode.en.md
  10. 12
      subjects/btreedeletenode.fr.md
  11. 13
      subjects/btreeinsertdata.fr.md
  12. 4
      subjects/btreeisbinary.en.md
  13. 12
      subjects/btreeisbinary.fr.md
  14. 2
      subjects/btreelevelcount.en.md
  15. 10
      subjects/btreelevelcount.fr.md
  16. 4
      subjects/btreemax.en.md
  17. 12
      subjects/btreemax.fr.md
  18. 2
      subjects/btreemin.en.md
  19. 12
      subjects/btreemin.fr.md
  20. 3
      subjects/btreeprintroot.en.md
  21. 15
      subjects/btreeprintroot.fr.md
  22. 2
      subjects/btreesearchitem.en.md
  23. 12
      subjects/btreesearchitem.fr.md
  24. 5
      subjects/btreetransplant.en.md
  25. 12
      subjects/btreetransplant.fr.md
  26. 2
      subjects/findnextprime.en.md
  27. 2
      subjects/findnextprime.fr.md
  28. 2
      subjects/isprime.en.md
  29. 2
      subjects/isprime.fr.md
  30. 8
      subjects/listat.en.md
  31. 39
      subjects/listat.fr.md
  32. 7
      subjects/listclear.en.md
  33. 48
      subjects/listclear.fr.md
  34. 7
      subjects/listfind.en.md
  35. 50
      subjects/listfind.fr.md
  36. 6
      subjects/listforeach.en.md
  37. 66
      subjects/listforeach.fr.md
  38. 10
      subjects/listforeachif.en.md
  39. 113
      subjects/listforeachif.fr.md
  40. 4
      subjects/listlast.en.md
  41. 12
      subjects/listlast.fr.md
  42. 4
      subjects/listmerge.en.md
  43. 60
      subjects/listmerge.fr.md
  44. 2
      subjects/listpushback.en.md
  45. 40
      subjects/listpushback.fr.md
  46. 2
      subjects/listpushfront.en.md
  47. 43
      subjects/listpushfront.fr.md
  48. 76
      subjects/listremoveif.fr.md
  49. 8
      subjects/listreverse.en.md
  50. 48
      subjects/listreverse.fr.md
  51. 4
      subjects/listsize.en.md
  52. 37
      subjects/listsize.fr.md
  53. 4
      subjects/listsort.en.md
  54. 29
      subjects/listsort.fr.md
  55. 4
      subjects/sortedlistmerge.en.md
  56. 39
      subjects/sortedlistmerge.fr.md
  57. 4
      subjects/sortlistinsert.en.md
  58. 26
      subjects/sortlistinsert.fr.md

4
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

12
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

4
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

14
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

2
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

12
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

2
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

12
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

2
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.

12
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

13
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

4
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

12
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

2
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

10
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

4
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

12
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

2
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

12
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

3
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

15
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

2
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

12
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

5
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

12
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

2
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

2
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

2
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

2
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

8
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
<nil>
student@ubuntu:~/piscine/test$
```
```

39
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
<nil>
student@ubuntu:~/piscine/test$
```

7
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

48
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 -> <nil>
------updated list------
<nil>
student@ubuntu:~/piscine/test$
```

7
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.
- The address may be different in each execution of the program.

50
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.

6
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

66
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$
```

10
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

113
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 -> <nil>
--------function applied--------
hello
there
!
--------function applied--------
1 -> 1 -> 3 -> 1 -> 23 -> 1 -> 54 -> <nil>
student@ubuntu:~/piscine/test$
```

4
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

12
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

4
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

60
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 -> <nil>
student@ubuntu:~/piscine/test$
```

2
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

40
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$
```

2
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

43
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$
```

76
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 -> <nil>
------answer-----
<nil>
----normal state----
1 -> Hello -> 1 -> There -> 1 -> 1 -> How -> 1 -> are -> you -> 1 -> <nil>
------answer-----
Hello -> There -> How -> are -> you -> <nil>
student@ubuntu:~/piscine/test$
```

8
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 <nil>}
Head &{4 0xc42000a140}
student@ubuntu:~/piscine/test$
```
```

48
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 <nil>}
Head &{4 0xc42000a140}
student@ubuntu:~/piscine/test$
```

4
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

37
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$
```

4
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

29
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

4
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

39
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 -> <nil>
-2 -> 3 -> 5 -> 7 -> 9 -> <nil>
student@ubuntu:~/piscine/test$
```

4
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

26
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

Loading…
Cancel
Save