Browse Source

Merge branch 'master' of github.com:01-edu/public

content-update
Christopher Fremond 5 years ago
parent
commit
0844ed0818
  1. 16
      subjects/activebits.en.md
  2. 16
      subjects/activebits.fr.md
  3. 20
      subjects/btreeapplybylevel.en.md
  4. 20
      subjects/btreeapplybylevel.fr.md
  5. 14
      subjects/btreeapplyinorder.en.md
  6. 12
      subjects/btreeapplyinorder.fr.md
  7. 14
      subjects/btreeapplypostorder.en.md
  8. 16
      subjects/btreeapplypreorder.en.md
  9. 14
      subjects/btreeapplypreorder.fr.md
  10. 28
      subjects/btreedeletenode.en.md
  11. 28
      subjects/btreedeletenode.fr.md
  12. 21
      subjects/btreeinsertdata.en.md
  13. 21
      subjects/btreeinsertdata.fr.md
  14. 20
      subjects/btreeisbinary.en.md
  15. 18
      subjects/btreeisbinary.fr.md
  16. 23
      subjects/btreelevelcount.en.md
  17. 21
      subjects/btreelevelcount.fr.md
  18. 21
      subjects/btreemax.en.md
  19. 21
      subjects/btreemax.fr.md
  20. 21
      subjects/btreemin.en.md
  21. 21
      subjects/btreemin.fr.md
  22. 25
      subjects/btreesearchitem.en.md
  23. 23
      subjects/btreesearchitem.fr.md
  24. 27
      subjects/btreetransplant.en.md
  25. 26
      subjects/btreetransplant.fr.md
  26. 48
      subjects/compact.en.md
  27. 44
      subjects/compact.fr.md
  28. 32
      subjects/listat.en.md
  29. 17
      subjects/listclear.en.md
  30. 35
      subjects/listfind.en.md
  31. 63
      subjects/listforeach.en.md
  32. 89
      subjects/listforeachif.en.md
  33. 14
      subjects/listlast.en.md
  34. 45
      subjects/listlast.fr.md
  35. 42
      subjects/listmerge.en.md
  36. 12
      subjects/listpushback.en.md
  37. 21
      subjects/listpushfront.en.md
  38. 52
      subjects/listremoveif.en.md
  39. 41
      subjects/listreverse.en.md
  40. 10
      subjects/listsize.en.md
  41. 65
      subjects/listsort.en.md
  42. 69
      subjects/listsort.fr.md
  43. 10
      subjects/max.en.md
  44. 10
      subjects/max.fr.md
  45. 62
      subjects/sortedlistmerge.en.md
  46. 68
      subjects/sortedlistmerge.fr.md
  47. 2
      subjects/sortlist.en.md
  48. 0
      subjects/sortlist.fr.md
  49. 66
      subjects/sortlistinsert.en.md
  50. 66
      subjects/sortlistinsert.fr.md
  51. 12
      subjects/unmatch.en.md
  52. 12
      subjects/unmatch.fr.md

16
subjects/activebits.en.md

@ -2,9 +2,7 @@
### Instructions ### Instructions
Write a function, ActiveBitsthat, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number. Write a function, `ActiveBits`, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number.
The function must have the next signature.
### Expected function ### Expected function
@ -23,11 +21,11 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
nbits := student.ActiveBits(7) nbits := piscine.ActiveBits(7)
fmt.Println(nbits) fmt.Println(nbits)
} }
``` ```
@ -35,8 +33,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/activebits$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/student/activebits$ ./activebits student@ubuntu:~/piscine/test$ ./test
10 3
student@ubuntu:~/student/activebits$ student@ubuntu:~/piscine/test$
``` ```

16
subjects/activebits.fr.md

@ -2,9 +2,7 @@
### Instructions ### Instructions
Write a function, ActiveBitsthat, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number. Write a function, `ActiveBits`, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number.
The function must have the next signature.
### Expected function ### Expected function
@ -23,11 +21,11 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
nbits := student.ActiveBits(7) nbits := piscine.ActiveBits(7)
fmt.Println(nbits) fmt.Println(nbits)
} }
``` ```
@ -35,8 +33,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/activebits$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/student/activebits$ ./activebits student@ubuntu:~/piscine/test$ ./test
10 3
student@ubuntu:~/student/activebits$ student@ubuntu:~/piscine/test$
``` ```

20
subjects/btreeapplybylevel.en.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeApplyByLevel, that applies the function given by fn to each node of the tree given by root. 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. This function must have the following signature.
@ -23,26 +23,26 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
student.BTreeApplyByLevel(root, fmt.Println) piscine.BTreeApplyByLevel(root, fmt.Println)
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreeapplybylevel$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreeapplybylevel$ ./btreeapplybylevel student@ubuntu:~/student/test$ ./test
4 4
1 1
7 7
5 5
student@ubuntu:~/student/btreeapplybylevel$ student@ubuntu:~/student/test$
``` ```

20
subjects/btreeapplybylevel.fr.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeApplyByLevel, that applies the function given by fn to each node of the tree given by root. 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. This function must have the following signature.
@ -23,26 +23,26 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
student.BTreeApplyByLevel(root, fmt.Println) piscine.BTreeApplyByLevel(root, fmt.Println)
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreeapplybylevel$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreeapplybylevel$ ./btreeapplybylevel student@ubuntu:~/student/test$ ./test
4 4
1 1
7 7
5 5
student@ubuntu:~/student/btreeapplybylevel$ student@ubuntu:~/student/test$
``` ```

14
subjects/btreeapplyinorder.en.md

@ -1,4 +1,4 @@
## btreeinsertdata ## btreeapplyinorder
### Instructions ### Instructions
@ -8,7 +8,7 @@ Write a function that applies a function in order to each element in the tree
### Expected function ### Expected function
```go ```go
func BTreeApplyInorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { func BTreeApplyInorder(root *TreeNode, f func(...interface{}) (int, error)) {
} }
``` ```
@ -22,7 +22,7 @@ package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
@ -30,7 +30,7 @@ func main() {
piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
} }
``` ```
@ -38,11 +38,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreeinsertdata$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata student@ubuntu:~/piscine/test$ ./test
1 1
4 4
5 5
7 7
student@ubuntu:~/piscine/btreeinsertdata$ student@ubuntu:~/piscine/test$
``` ```

12
subjects/btreeapplyinorder.fr.md

@ -8,7 +8,7 @@ Write a function that applies a function in order to each element in the tree
### Expected function ### Expected function
```go ```go
func BTreeApplyInorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { func BTreeApplyInorder(root *TreeNode, f func(...interface{}) (int, error)) {
} }
``` ```
@ -22,7 +22,7 @@ package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
@ -30,7 +30,7 @@ func main() {
piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
} }
``` ```
@ -38,11 +38,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreeinsertdata$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata student@ubuntu:~/piscine/test$ ./test
1 1
4 4
5 5
7 7
student@ubuntu:~/piscine/btreeinsertdata$ student@ubuntu:~/piscine/test$
``` ```

14
subjects/btreeapplypostorder.en.md

@ -1,4 +1,4 @@
## btreeinsertdata ## btreeapplypostorder
### Instructions ### Instructions
@ -7,7 +7,7 @@ Write a function that applies a function using a postorder walk to each element
### Expected function ### Expected function
```go ```go
func BTreeApplyPostorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { func BTreeApplyPostorder(root *TreeNode, f func(...interface{}) (int, error)) {
} }
``` ```
@ -21,7 +21,7 @@ package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
@ -29,7 +29,7 @@ func main() {
piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
BTreeApplyPostorder(root, fmt.Println) piscine.BTreeApplyPostorder(root, fmt.Println)
} }
``` ```
@ -37,11 +37,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreeinsertdata$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata student@ubuntu:~/piscine/test$ ./test
1 1
5 5
7 7
4 4
student@ubuntu:~/piscine/btreeinsertdata$ student@ubuntu:~/piscine/test$
``` ```

16
subjects/btreeapplypreorder.en.md

@ -1,4 +1,4 @@
## btreeinsertdata ## btreeapplypreorder
### Instructions ### Instructions
@ -7,7 +7,7 @@ Write a function that applies a function using a preorder walk to each element i
### Expected function ### Expected function
```go ```go
func BTreeApplyPreorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { func BTreeApplyPreorder(root *TreeNode, f func(...interface{}) (int, error)) {
} }
``` ```
@ -20,8 +20,8 @@ Here is a possible [program](TODO-LINK) to test your function :
package main package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
@ -29,7 +29,7 @@ func main() {
piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
BTreeApplyPreorder(root, fmt.Println) piscine.BTreeApplyPreorder(root, fmt.Println)
} }
``` ```
@ -37,11 +37,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreeinsertdata$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata student@ubuntu:~/piscine/test$ ./test
4 4
1 1
7 7
5 5
student@ubuntu:~/piscine/btreeinsertdata$ student@ubuntu:~/piscine/test$
``` ```

14
subjects/btreeapplypreorder.fr.md

@ -7,7 +7,7 @@ Write a function that applies a function using a preorder walk to each element i
### Expected function ### Expected function
```go ```go
func BTreeApplyPreorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { func BTreeApplyPreorder(root *TreeNode, f func(...interface{}) (int, error)) {
} }
``` ```
@ -20,8 +20,8 @@ Here is a possible [program](TODO-LINK) to test your function :
package main package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
@ -29,7 +29,7 @@ func main() {
piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
BTreeApplyPreorder(root, fmt.Println) piscine.BTreeApplyPreorder(root, fmt.Println)
} }
``` ```
@ -37,11 +37,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreeinsertdata$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata student@ubuntu:~/piscine/test$ ./test
4 4
1 1
7 7
5 5
student@ubuntu:~/piscine/btreeinsertdata$ student@ubuntu:~/piscine/test$
``` ```

28
subjects/btreedeletenode.en.md

@ -2,12 +2,10 @@
### Instructions ### 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. The resulting tree should still follow the binary search tree rules.
This function must have the following signature.
### Expected function ### Expected function
```go ```go
@ -26,28 +24,28 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
node := student.BTreeSearchItem(root, "4") node := piscine.BTreeSearchItem(root, "4")
fmt.Println("Before delete:") fmt.Println("Before delete:")
student.BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
root = student.BTreeDeleteNode(root, node) root = piscine.BTreeDeleteNode(root, node)
fmt.Println("After delete:") fmt.Println("After delete:")
student.BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreedeletenode$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode student@ubuntu:~/student/test$ ./test
Before delete: Before delete:
1 1
4 4
@ -57,5 +55,5 @@ After delete:
1 1
5 5
7 7
student@ubuntu:~/student/btreedeletenode$ student@ubuntu:~/student/test$
``` ```

28
subjects/btreedeletenode.fr.md

@ -2,12 +2,10 @@
### Instructions ### 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. The resulting tree should still follow the binary search tree rules.
This function must have the following signature.
### Expected function ### Expected function
```go ```go
@ -26,28 +24,28 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
node := student.BTreeSearchItem(root, "4") node := piscine.BTreeSearchItem(root, "4")
fmt.Println("Before delete:") fmt.Println("Before delete:")
student.BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
root = student.BTreeDeleteNode(root, node) root = piscine.BTreeDeleteNode(root, node)
fmt.Println("After delete:") fmt.Println("After delete:")
student.BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreedeletenode$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode student@ubuntu:~/student/test$ ./test
Before delete: Before delete:
1 1
4 4
@ -57,5 +55,5 @@ After delete:
1 1
5 5
7 7
student@ubuntu:~/student/btreedeletenode$ student@ubuntu:~/student/test$
``` ```

21
subjects/btreeinsertdata.en.md

@ -26,15 +26,20 @@ Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import (
"fmt"
piscine ".."
)
func main() { func main() {
root := &TreeNode{data: "4"} root := &piscine.TreeNode{Data: "4"}
BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
fmt.Println(root.left.data) fmt.Println(root.Left.Data)
fmt.Println(root.data) fmt.Println(root.Data)
fmt.Println(root.right.left.data) fmt.Println(root.Right.Left.Data)
fmt.Println(root.right.data) fmt.Println(root.Right.Data)
} }
``` ```

21
subjects/btreeinsertdata.fr.md

@ -26,15 +26,20 @@ Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import (
"fmt"
piscine ".."
)
func main() { func main() {
root := &TreeNode{data: "4"} root := &piscine.TreeNode{Data: "4"}
BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
fmt.Println(root.left.data) fmt.Println(root.Left.Data)
fmt.Println(root.data) fmt.Println(root.Data)
fmt.Println(root.right.left.data) fmt.Println(root.Right.Left.Data)
fmt.Println(root.right.data) fmt.Println(root.Right.Data)
} }
``` ```

20
subjects/btreeisbinary.en.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeIsBinary, that returns true only if the tree given by root follows the binary search tree properties. 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. This function must have the following signature.
@ -23,23 +23,23 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
fmt.Println(student.BTreeIsBinary(root)) fmt.Println(piscine.BTreeIsBinary(root))
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreeisbinary$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreeisbinary$ ./btreeisbinary student@ubuntu:~/student/test$ ./test
true true
student@ubuntu:~/student/btreeisbinary$ student@ubuntu:~/student/test$
``` ```

18
subjects/btreeisbinary.fr.md

@ -23,23 +23,23 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
fmt.Println(student.BTreeIsBinary(root)) fmt.Println(piscine.BTreeIsBinary(root))
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreeisbinary$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreeisbinary$ ./btreeisbinary student@ubuntu:~/student/test$ ./test
true true
student@ubuntu:~/student/btreeisbinary$ student@ubuntu:~/student/test$
``` ```

23
subjects/btreelevelcount.en.md

@ -2,12 +2,12 @@
### Instructions ### Instructions
Write a function, BTreeLevelCount, that return the number of levels of the tree (height of the tree) Write a function, `BTreeLevelCount`, that return the number of levels of the tree (height of the tree)
### Expected function ### Expected function
```go ```go
func BTreeLevelCount(root *piscine.TreeNode) int { func BTreeLevelCount(root *TreeNode) int {
} }
``` ```
@ -21,23 +21,24 @@ package main
import ( import (
"fmt" "fmt"
student ".."
piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
fmt.Println(BTreeLevelCount(root)) fmt.Println(piscine.BTreeLevelCount(root))
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreesearchitem$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreesearchitem$ ./btreesearchitem student@ubuntu:~/student/test$ ./test
3 3
student@ubuntu:~/student/btreesearchitem$ student@ubuntu:~/student/test$
``` ```

21
subjects/btreelevelcount.fr.md

@ -7,7 +7,7 @@ Write a function, BTreeLevelCount, that return the number of levels of the tree
### Expected function ### Expected function
```go ```go
func BTreeLevelCount(root *piscine.TreeNode) int { func BTreeLevelCount(root *TreeNode) int {
} }
``` ```
@ -21,23 +21,24 @@ package main
import ( import (
"fmt" "fmt"
student ".."
piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
fmt.Println(BTreeLevelCount(root)) fmt.Println(piscine.BTreeLevelCount(root))
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreesearchitem$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreesearchitem$ ./btreesearchitem student@ubuntu:~/student/test$ ./test
3 3
student@ubuntu:~/student/btreesearchitem$ student@ubuntu:~/student/test$
``` ```

21
subjects/btreemax.en.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeMax, that returns the node with the maximum value in the tree given by root 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. This function must have the following signature.
@ -23,15 +23,16 @@ package main
import ( import (
"fmt" "fmt"
student ".."
piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
max := student.BTreeMax(root) max := piscine.BTreeMax(root)
fmt.Println(max.Data) fmt.Println(max.Data)
} }
``` ```
@ -39,8 +40,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreemax$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreemax$ ./btreemax student@ubuntu:~/student/test$ ./test
7 7
student@ubuntu:~/student/btreemax$ student@ubuntu:~/student/test$
``` ```

21
subjects/btreemax.fr.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeMax, that returns the node with the maximum value in the tree given by root 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. This function must have the following signature.
@ -23,15 +23,16 @@ package main
import ( import (
"fmt" "fmt"
student ".."
piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
max := student.BTreeMax(root) max := piscine.BTreeMax(root)
fmt.Println(max.Data) fmt.Println(max.Data)
} }
``` ```
@ -39,8 +40,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreemax$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreemax$ ./btreemax student@ubuntu:~/student/test$ ./test
7 7
student@ubuntu:~/student/btreemax$ student@ubuntu:~/student/test$
``` ```

21
subjects/btreemin.en.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeMin, that returns the node with the minimum value in the tree given by root 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. This function must have the following signature.
@ -23,15 +23,16 @@ package main
import ( import (
"fmt" "fmt"
student ".."
piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
min := student.BTreeMin(root) min := piscine.BTreeMin(root)
fmt.Println(min.Data) fmt.Println(min.Data)
} }
``` ```
@ -39,8 +40,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreemin$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreemin$ ./btreemin student@ubuntu:~/student/test$ ./test
1 1
student@ubuntu:~/student/btreemin$ student@ubuntu:~/student/test$
``` ```

21
subjects/btreemin.fr.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a function, BTreeMin, that returns the node with the minimum value in the tree given by root 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. This function must have the following signature.
@ -23,15 +23,16 @@ package main
import ( import (
"fmt" "fmt"
student ".."
piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
min := student.BTreeMin(root) min := piscine.BTreeMin(root)
fmt.Println(min.Data) fmt.Println(min.Data)
} }
``` ```
@ -39,8 +40,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreemin$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreemin$ ./btreemin student@ubuntu:~/student/test$ ./test
1 1
student@ubuntu:~/student/btreemin$ student@ubuntu:~/student/test$
``` ```

25
subjects/btreesearchitem.en.md

@ -1,4 +1,4 @@
## btreeinsertdata ## btreesearchitem
### Instructions ### Instructions
@ -7,10 +7,9 @@ Write a function that searches for an item with a data element equal to elem and
### Expected function ### Expected function
```go ```go
func BTreeSearchItem(root *piscine_test.TreeNode, elem string) *piscine_test.TreeNode { func BTreeSearchItem(root *TreeNode, elem string) *TreeNode {
} }
``` ```
### Usage ### Usage
@ -21,16 +20,16 @@ Here is a possible [program](TODO-LINK) to test your function :
package main package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
root := &piscine_test.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
piscine_test.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine_test.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine_test.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
selected := BTreeSearchItem(root, "7") selected := piscine.BTreeSearchItem(root, "7")
fmt.Print("Item selected -> ") fmt.Print("Item selected -> ")
if selected != nil { if selected != nil {
fmt.Println(selected.Data) fmt.Println(selected.Data)
@ -64,11 +63,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreesearchitem$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreesearchitem$ ./btreesearchitem student@ubuntu:~/piscine/test$ ./test
Item selected -> 7 Item selected -> 7
Parent of selected item -> 4 Parent of selected item -> 4
Left child of selected item -> 5 Left child of selected item -> 5
Right child of selected item -> nil Right child of selected item -> nil
student@ubuntu:~/piscine/btreesearchitem$ student@ubuntu:~/piscine/test$
``` ```

23
subjects/btreesearchitem.fr.md

@ -7,10 +7,9 @@ Write a function that searches for an item with a data element equal to elem and
### Expected function ### Expected function
```go ```go
func BTreeSearchItem(root *piscine_test.TreeNode, elem string) *piscine_test.TreeNode { func BTreeSearchItem(root *TreeNode, elem string) *TreeNode {
} }
``` ```
### Usage ### Usage
@ -21,16 +20,16 @@ Here is a possible [program](TODO-LINK) to test your function :
package main package main
import ( import (
"fmt" "fmt"
piscine "." piscine ".."
) )
func main() { func main() {
root := &piscine_test.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
piscine_test.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
piscine_test.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
piscine_test.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
selected := BTreeSearchItem(root, "7") selected := piscine.BTreeSearchItem(root, "7")
fmt.Print("Item selected -> ") fmt.Print("Item selected -> ")
if selected != nil { if selected != nil {
fmt.Println(selected.Data) fmt.Println(selected.Data)
@ -64,11 +63,11 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/piscine/btreesearchitem$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/btreesearchitem$ ./btreesearchitem student@ubuntu:~/piscine/test$ ./test
Item selected -> 7 Item selected -> 7
Parent of selected item -> 4 Parent of selected item -> 4
Left child of selected item -> 5 Left child of selected item -> 5
Right child of selected item -> nil Right child of selected item -> nil
student@ubuntu:~/piscine/btreesearchitem$ student@ubuntu:~/piscine/test$
``` ```

27
subjects/btreetransplant.en.md

@ -2,7 +2,8 @@
### Instructions ### 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.
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. This function must have the following signature.
@ -23,29 +24,29 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
node := student.BTreeSearchItem(root, "1") node := piscine.BTreeSearchItem(root, "1")
replacement := &student.TreeNode{Data: "3"} replacement := &piscine.TreeNode{Data: "3"}
root = student.BTreeTransplant(root, node, replacement) root = piscine.BTreeTransplant(root, node, replacement)
student.BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreetransplant$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant student@ubuntu:~/student/test$ ./test
3 3
4 4
5 5
7 7
student@ubuntu:~/student/btreetrandsplant$ student@ubuntu:~/student/test$
``` ```

26
subjects/btreetransplant.fr.md

@ -2,7 +2,7 @@
### Instructions ### 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. 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. This function must have the following signature.
@ -23,29 +23,29 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
root := &student.TreeNode{Data: "4"} root := &piscine.TreeNode{Data: "4"}
student.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "1")
student.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "7")
student.BTreeInsertData(root, "5") piscine.BTreeInsertData(root, "5")
node := student.BTreeSearchItem(root, "1") node := piscine.BTreeSearchItem(root, "1")
replacement := &student.TreeNode{Data: "3"} replacement := &piscine.TreeNode{Data: "3"}
root = student.BTreeTransplant(root, node, replacement) root = piscine.BTreeTransplant(root, node, replacement)
student.BTreeApplyInorder(root, fmt.Println) piscine.BTreeApplyInorder(root, fmt.Println)
} }
``` ```
And its output : And its output :
```console ```console
student@ubuntu:~/student/btreetransplant$ go build student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant student@ubuntu:~/student/test$ ./test
3 3
4 4
5 5
7 7
student@ubuntu:~/student/btreetrandsplant$ student@ubuntu:~/student/test$
``` ```

48
subjects/compact.en.md

@ -1,15 +1,18 @@
## compact ## Compact
### Instructions ### Instructions
Write a function `Compact` that takes a pointer to an array as parameter and overwrites the elements that points to `nil`. Write a function `Compact` that takes a pointer to a slice of strings as the argument.
This function must:
- Hint: This fonction exists in Ruby. - Return the number of elements with non-`nil`.
### Expected function - Compact, i.e., delete the elements with `nil` in the slice.
### Expected functions
```go ```go
func Compact(ptr *[]string, length int) int { func Compact(ptr *[]string) int {
} }
``` ```
@ -21,13 +24,29 @@ Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import fmt import (
"fmt"
piscine ".."
)
const N = 6
func main() { func main() {
array := []string{"hello", " ", "there", " ", "bye"} arr := make([]string, N)
arr[0] = "a"
arr[2] = "b"
arr[4] = "c"
for _, v := range arr {
fmt.Println(v)
}
ptr := &array fmt.Println("Size after compacting:", piscine.Compact(&arr))
fmt.Println(Compact(ptr, len(array)))
for _, v := range arr {
fmt.Println(v)
}
} }
``` ```
@ -36,6 +55,15 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
3 a
b
c
Size after compacting: 3
a
b
c
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

44
subjects/compact.fr.md

@ -2,14 +2,17 @@
### Instructions ### Instructions
Écrire une fonction `Compact` qui prend un pointeur sur tableau comme paramètre et qui réécris sur les éléments qui pointent sur `nil`. Écrire une fonction `Compact` qui prend un pointeur sur slice de `strings` comme paramètre.
Cette fonction doit:
- Indice: Cette fonction existe in Ruby. - Retourner le nombre d'éléments avec des valeurs non-`nil`
- Comprimer, c.à.d., effacer les éléments qui ont une valeur `nil` dans la slice.
### Fonction attendue ### Fonction attendue
```go ```go
func Compact(ptr *[]string, length int) int { func Compact(ptr *[]string) int {
} }
``` ```
@ -21,13 +24,29 @@ Voici un Ă©ventuel [programme](TODO-LINK) pour tester votre fonction :
```go ```go
package main package main
import fmt import (
"fmt"
piscine ".."
)
const N = 6
func main() { func main() {
array := []string{"hello", " ", "there", " ", "bye"} arr := make([]string, N)
arr[0] = "a"
arr[2] = "b"
arr[4] = "c"
for _, v := range arr {
fmt.Println(v)
}
ptr := &array fmt.Println("Size after compacting:", piscine.Compact(&arr))
fmt.Println(Compact(ptr, len(array)))
for _, v := range arr {
fmt.Println(v)
}
} }
``` ```
@ -36,6 +55,15 @@ Et son résultat :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
3 a
b
c
Size after compacting: 3
a
b
c
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

32
subjects/listat.en.md

@ -2,20 +2,20 @@
### Instructions ### Instructions
Write a function `ListAt` that haves one pointer to the list, `l`, and an `int` as parameters. This function should print a `Node` of the linked list, depending on the number, `nbr`. 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.
- In case of error it should print `nil` - In case of error it should print `nil`
### Expected function and structure ### Expected function and structure
```go ```go
type Node struct { type NodeL struct {
Data interface{} Data interface{}
Next *Node Next *NodeL
} }
func ListAt(l *Node, nbr int) *Node{ func ListAt(l *NodeL, pos int) *NodeL{
} }
``` ```
@ -33,18 +33,16 @@ import (
) )
func main() { func main() {
link := &Node{} link := &piscine.List{}
ListPushBack(link, "hello") piscine.ListPushBack(link, "hello")
ListPushBack(link, "how are") piscine.ListPushBack(link, "how are")
ListPushBack(link, "you") piscine.ListPushBack(link, "you")
ListPushBack(link, 1) piscine.ListPushBack(link, 1)
fmt.Println() fmt.Println(piscine.ListAt(link.Head, 3).Data)
fmt.Println(piscine.ListAt(link.Head, 1).Data)
fmt.Println(ListAt(link, 3).Data) fmt.Println(piscine.ListAt(link.Head, 7))
fmt.Println(ListAt(link, 1).Data)
fmt.Println(ListAt(link, 7))
} }
``` ```
@ -54,8 +52,8 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
you 1
hello how are
<nil> <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

17
subjects/listclear.en.md

@ -2,25 +2,14 @@
### Instructions ### Instructions
Write a function `ListClear` that delets all `nodes` from a linked list, deleting the link between the list. Write a function `ListClear` that deletes all `nodes` from a linked list, deleting the link between the list.
- Tip: assign the list's pointer to nil - Tip: assign the list's pointer to nil
### Expected function and structure ### Expected function and structure
```go ```go
type Node struct {
Data interface{}
Next *Node
}
type List struct {
Head *Node
Tail *Node
}
func ListClear(l *List) { func ListClear(l *List) {
} }
``` ```
@ -33,11 +22,12 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
type List = piscine.List type List = piscine.List
type Node = piscine.Node type Node = piscine.NodeL
func PrintList(l *List) { func PrintList(l *List) {
link := l.Head link := l.Head
@ -65,6 +55,7 @@ func main() {
``` ```
And its output : And its output :
```console ```console

35
subjects/listfind.en.md

@ -1,31 +1,29 @@
## listpushback ## listfind
### Instructions ### Instructions
Write a function `ListFind` that returns the address of the first link that the function in the arguments its equal. 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`.
- For this you shoud use the function `CompStr`. - For this you shoud use the function `CompStr`.
- Use pointers wen ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} Data interface{}
next *node Next *NodeL
} }
type list struct { type List struct {
head *node Head *NodeL
tail *node Tail *NodeL
} }
func CompStr(l *list) bool { func CompStr(a, b interface{}) bool {
return a == b
} }
func ListFind(l *list, comp func(l *list) bool) *interface{} { func ListFind(l *List, ref interface{}, comp func(a, b interface{}) bool) *interface{} {
} }
``` ```
@ -43,14 +41,17 @@ import (
) )
func main() { func main() {
link := &list{} link := &piscine.List{}
piscine.ListPushBack(link, "hello") piscine.ListPushBack(link, "hello")
piscine.ListPushBack(link, "hello1") piscine.ListPushBack(link, "hello1")
piscine.ListPushBack(link, "hello2") piscine.ListPushBack(link, "hello2")
piscine.ListPushBack(link, "hello3") piscine.ListPushBack(link, "hello3")
fmt.Println(piscine.ListFind(link, compStr)) found := piscine.ListFind(link, interface{}("hello2"), piscine.CompStr)
fmt.Println(found)
fmt.Println(*found)
} }
``` ```
@ -60,5 +61,9 @@ And its output :
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
0xc42000a0a0 0xc42000a0a0
hello2
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```
### Note
- The address may be different in each execution of the program.

63
subjects/listforeach.en.md

@ -4,22 +4,42 @@
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 information within each of the list's links.
- The function given as argument must have a pointer as argument: `l *list` - 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`.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} Data interface{}
next *node Next *NodeL
}
type List struct {
Head *NodeL
Tail *NodeL
} }
type list struct { func ListForEach(l *List, f func(*NodeL)) {
head *node
tail *node
} }
func ListForEach(l *list, f func(l *list)) { 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"
}
} }
``` ```
@ -36,18 +56,19 @@ import (
) )
func main() { func main() {
link := &list{} link := &piscine.List{}
piscine.ListPushBack(link, 1) piscine.ListPushBack(link, "1")
piscine.ListPushBack(link, 2) piscine.ListPushBack(link, "2")
piscine.ListPushBack(link, 3) piscine.ListPushBack(link, "3")
piscine.ListPushBack(link, 4) piscine.ListPushBack(link, "5")
piscine.ListForEach(link, piscine.ListReverse) piscine.ListForEach(link, piscine.Add2)
for link.head != nil { it := link.Head
fmt.Println(link.head.data) for it != nil {
link.head = link.head.next fmt.Println(it.Data)
it = it.Next
} }
} }
``` ```
@ -57,9 +78,9 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
4 12
3 22
2 32
1 52
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

89
subjects/listforeachif.en.md

@ -1,33 +1,61 @@
## listpushback ## listforeachif
### Instructions ### Instructions
Write a function `ListForEachIf` that applies a function given as argument to the information within some links of the list. Write a function `ListForEachIf` that applies a function given as argument to the information within some nodes of the list.
- For this you will have to create a function `CompStr`, that returns a `bool`, to compare each elemente of the linked list, to see if it is a string, and than apply the function in the argument of `ListForEachIf`. - This functions receives two functions:
- The function given as argument as to have a pointer as argument: `l *list`. - `f` is a functions that is applied to the node.
- Use pointers wen ever you can. - `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.
- The function given as argument must have a pointer as argument: `*NodeL`.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} Data interface{}
next *node Next *NodeL
}
type List struct {
Head *NodeL
Tail *NodeL
} }
type list struct { func IsPositive_node(node *NodeL) bool {
head *node switch node.Data.(type) {
tail *node case int, float32, float64, byte:
return node.Data.(int) > 0
case string, rune:
return false
}
return false
} }
func CompStr(l *list) bool { 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(l *list), comp func(l *list) bool) { func ListForEachIf(l *List, f func(*NodeL), cond func(*NodeL) bool) {
} }
``` ```
@ -40,30 +68,29 @@ Here is a possible [program](TODO-LINK) to test your function :
package main package main
import ( import (
"fmt"
piscine ".." piscine ".."
"fmt"
) )
func PrintElem(l *list) { func PrintElem(node *piscine.NodeL) {
fmt.Println(l.head.data) fmt.Println(node.Data)
} }
func StringToInt(l *list) { func StringToInt(node *piscine.NodeL) {
count := 1 node.Data = 2
l.head.data = count
} }
func PrintList(l *list) { func PrintList(l *piscine.List) {
m := l.head it := l.Head
for m != nil { for it != nil {
fmt.Print(m.data, " -> ") fmt.Print(it.Data, "->")
m = m.next it = it.Next
} }
fmt.Println()
fmt.Print(l.tail)
} }
func main() { func main() {
link := &list{} link := &piscine.List{}
piscine.ListPushBack(link, 1) piscine.ListPushBack(link, 1)
piscine.ListPushBack(link, "hello") piscine.ListPushBack(link, "hello")
@ -73,16 +100,16 @@ func main() {
piscine.ListPushBack(link, "!") piscine.ListPushBack(link, "!")
piscine.ListPushBack(link, 54) piscine.ListPushBack(link, 54)
PrintAllList(link) PrintList(link)
fmt.Println() fmt.Println()
fmt.Println("--------function applied--------") fmt.Println("--------function applied--------")
piscine.ListForEachIf(link, PrintElem, CompStr) piscine.ListForEachIf(link, PrintElem, piscine.IsPositive_node)
piscine.ListForEachIf(link, StringToInt, CompStr) piscine.ListForEachIf(link, StringToInt, piscine.IsNotNumeric_node)
fmt.Println("--------function applied--------") fmt.Println("--------function applied--------")
PrintAllList(link) PrintList(link)
fmt.Println() fmt.Println()
} }

14
subjects/listlast.en.md

@ -17,7 +17,7 @@ type List struct {
Tail *Node Tail *Node
} }
func ListLast(l *list) *list { func ListLast(l *List) interface{} {
} }
``` ```
@ -30,20 +30,20 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func main() { func main() {
link := &list{} link := &piscine.List{}
link2 := &list{} link2 := &piscine.List{}
piscine.ListPushBack(link, "three") piscine.ListPushBack(link, "three")
piscine.ListPushBack(link, 3) piscine.ListPushBack(link, 3)
piscine.ListPushBack(link, "1") piscine.ListPushBack(link, "1")
fmt.Println(piscine.ListLast(link).head) fmt.Println(piscine.ListLast(link))
fmt.Println(piscine.ListLast(link2).head) fmt.Println(piscine.ListLast(link2))
} }
``` ```
@ -53,7 +53,7 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
&{1 <nil>} 1
<nil> <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

45
subjects/listlast.fr.md

@ -1,44 +1,59 @@
## countif ## listpushback
### Instructions ### Instructions
Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. Write a function `ListLast` that returns the last element of the linked list.
### Fonction attendue ### Expected function and structure
```go ```go
func CountIf(f func(string) bool, tab []string) int { type Node struct {
Data interface{}
Next *Node
}
type List struct {
Head *Node
Tail *Node
}
func ListLast(l *List) interface{} {
} }
``` ```
### Utilisation ### Usage
Voici un Ă©ventuel [programme](TODO-LINK) pour tester votre fonction : Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func main() { func main() {
tab1 := []string{"Hello", "how", "are", "you"} link := &piscine.List{}
tab2 := []string{"This","1", "is", "4", "you"} link2 := &piscine.List{}
answer1 := piscine.CountIf(piscine.IsNumeric, tab1)
answer2 := piscine.CountIf(piscine.IsNumeric, tab2) piscine.ListPushBack(link, "three")
fmt.Println(answer1) piscine.ListPushBack(link, 3)
fmt.Println(answer2) piscine.ListPushBack(link, "1")
fmt.Println(piscine.ListLast(link))
fmt.Println(piscine.ListLast(link2))
} }
``` ```
Et son résultat : And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
0 1
2 <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

42
subjects/listmerge.en.md

@ -1,4 +1,4 @@
## listpushback ## listmerge
### Instructions ### Instructions
@ -6,22 +6,20 @@ Write a function `ListMerge` that places elements of a list `l2` at the end of a
- You can't create new elements! - You can't create new elements!
- Use pointers when ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} Data interface{}
next *node Next *NodeL
} }
type list struct { type List struct {
head *node Head *NodeL
tail *node Tail *NodeL
} }
func ListMerge(l1 *list, l2 *list) { func ListMerge(l1 *List, l2 *List) {
} }
``` ```
@ -35,34 +33,38 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func PrintList(l *list) { func PrintList(l *piscine.List) {
m := l.head it := l.Head
for m != nil { for it != nil {
fmt.Print(m.data, " -> ") fmt.Print(it.Data, " -> ")
m = m.next it = it.Next
} }
fmt.Print(nil, "\n")
fmt.Print(l.tail)
fmt.Println()
} }
func main() { func main() {
link := &list{} link := &piscine.List{}
link2 := &list{} link2 := &piscine.List{}
piscine.ListPushBack(link, "a") piscine.ListPushBack(link, "a")
piscine.ListPushBack(link, "b") piscine.ListPushBack(link, "b")
piscine.ListPushBack(link, "c") piscine.ListPushBack(link, "c")
piscine.ListPushBack(link, "d") piscine.ListPushBack(link, "d")
fmt.Println("-----first List------")
PrintList(link)
piscine.ListPushBack(link2, "e") piscine.ListPushBack(link2, "e")
piscine.ListPushBack(link2, "f") piscine.ListPushBack(link2, "f")
piscine.ListPushBack(link2, "g") piscine.ListPushBack(link2, "g")
piscine.ListPushBack(link2, "h") piscine.ListPushBack(link2, "h")
fmt.Println("-----second List------")
PrintList(link2)
fmt.Println("-----Merged List-----")
piscine.ListMerge(link, link2) piscine.ListMerge(link, link2)
PrintList(link) PrintList(link)
} }

12
subjects/listpushback.en.md

@ -2,19 +2,19 @@
### Instructions ### Instructions
Write a function `ListPushBack` that inserts a new element `Node` 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, using the structure `List`
### Expected function and structure ### Expected function and structure
```go ```go
type Node struct { type NodeL struct {
Data interface{} Data interface{}
Next *Node Next *NodeL
} }
type List struct { type List struct {
Head *Node Head *NodeL
Tail *Node Tail *NodeL
} }
func ListPushBack(l *List, data interface{}) { func ListPushBack(l *List, data interface{}) {
@ -35,7 +35,7 @@ import (
func main() { func main() {
link := &List{} link := &piscine.List{}
piscine.ListPushBack(link, "Hello") piscine.ListPushBack(link, "Hello")
piscine.ListPushBack(link, "man") piscine.ListPushBack(link, "man")

21
subjects/listpushfront.en.md

@ -7,17 +7,17 @@ Write a function `ListPushBack` that inserts a new element `node` at the beginni
### Expected function and structure ### Expected function and structure
```go ```go
type Node struct { type NodeL struct {
Data interface{} Data interface{}
Next *Node Next *NodeL
} }
type List struct { type List struct {
Head *Node Head *NodeL
Tail *Node Tail *NodeL
} }
func ListPushFront(l *list, data interface{}) { func ListPushFront(l *List, data interface{}) {
} }
``` ```
@ -29,21 +29,22 @@ Here is a possible [program](TODO-LINK) to test your function :
package main package main
import ( import (
"fmt"
piscine ".." piscine ".."
"fmt"
) )
func main() { func main() {
link := &list{} link := &piscine.List{}
piscine.ListPushFront(link, "Hello") piscine.ListPushFront(link, "Hello")
piscine.ListPushFront(link, "man") piscine.ListPushFront(link, "man")
piscine.ListPushFront(link, "how are you") piscine.ListPushFront(link, "how are you")
for link.head != nil { it := link.Head
fmt.Println(link.head.data) for it != nil {
link.head = link.head.next fmt.Println(it.Data)
it = it.Next
} }
} }
``` ```

52
subjects/listremoveif.en.md

@ -1,27 +1,23 @@
## listpushback ## listremoveif
### Instructions ### Instructions
Write a function `ListRemoveIf` that removes all elements that are equal to the `data_ref` introduced in the argument of the function. Write a function `ListRemoveIf` that removes all elements that are equal to the `data_ref` introduced in the argument of the function.
- In case the list is empty print the message `no data on list`.
- Use pointers wen ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} Data interface{}
next *node Next *NodeL
} }
type list struct { type List struct {
head *node Head *NodeL
tail *node Tail *NodeL
} }
func ListRemoveIf(l *list, data_ref interface{}) { func ListRemoveIf(l *List, data_ref interface{}) {
} }
``` ```
@ -35,35 +31,30 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func PrintList(l *list) { func PrintList(l *piscine.List) {
m := l.head it := l.Head
for m != nil { for it != nil {
fmt.Print(m.data, " -> ") fmt.Print(it.Data, " -> ")
m = m.next it = it.Next
} }
fmt.Print(l.tail) fmt.Print(nil, "\n")
fmt.Println()
} }
func main() { func main() {
link := &list{} link := &piscine.List{}
link2 := &list{} link2 := &piscine.List{}
link3 := &list{}
fmt.Println("------answer-----")
ListRemoveIf(link3, 1)
fmt.Println()
fmt.Println("----normal state----") fmt.Println("----normal state----")
piscine.ListPushBack(link2, 1) piscine.ListPushBack(link2, 1)
PrintList(link2) PrintList(link2)
ListRemoveIf(link2, 1) piscine.ListRemoveIf(link2, 1)
fmt.Println("------answer-----") fmt.Println("------answer-----")
PrintList(link) PrintList(link2)
fmt.Println() fmt.Println()
fmt.Println("----normal state----") fmt.Println("----normal state----")
@ -80,7 +71,7 @@ func main() {
piscine.ListPushBack(link, 1) piscine.ListPushBack(link, 1)
PrintList(link) PrintList(link)
ListRemoveIf(link, 1) piscine.ListRemoveIf(link, 1)
fmt.Println("------answer-----") fmt.Println("------answer-----")
PrintList(link) PrintList(link)
} }
@ -92,9 +83,6 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
------answer-----
no data on list
----normal state---- ----normal state----
1 -> <nil> 1 -> <nil>
------answer----- ------answer-----

41
subjects/listreverse.en.md

@ -9,17 +9,17 @@ Write a function `ListReverse` that reverses the elements order of a given linke
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeL struct {
data interface{} Data interface{}
next *node Next *NodeL
} }
type list struct { type List struct {
head *node Head *NodeL
tail *node Tail *NodeL
} }
func ListReverse(l *list) { func ListReverse(l *List) {
} }
``` ```
@ -36,19 +36,24 @@ import (
) )
func main() { func main() {
link := &list{} link := &piscine.List{}
listPushBack(link, 1) piscine.ListPushBack(link, 1)
listPushBack(link, 2) piscine.ListPushBack(link, 2)
listPushBack(link, 3) piscine.ListPushBack(link, 3)
listPushBack(link, 4) piscine.ListPushBack(link, 4)
listReverse(link) piscine.ListReverse(link)
for link.head != nil { it := link.Head
fmt.Println(link.head.data)
link.head = link.head.next for it != nil {
fmt.Println(it.Data)
it = it.Next
} }
fmt.Println("Tail", link.Tail)
fmt.Println("Head", link.Head)
} }
``` ```
@ -61,5 +66,7 @@ student@ubuntu:~/piscine/test$ ./test
3 3
2 2
1 1
Tail &{1 <nil>}
Head &{4 0xc42000a140}
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

10
subjects/listsize.en.md

@ -7,14 +7,14 @@ Write a function `ListSize` that returns the number of elements in the list.
### Expected function and structure ### Expected function and structure
```go ```go
type Node struct { type NodeL struct {
Data interface{} Data interface{}
Next *Node Next *NodeL
} }
type List struct { type List struct {
Head *Node Head *NodeL
Tail *Node Tail *NodeL
} }
func ListSize(l *List) int { func ListSize(l *List) int {
@ -35,7 +35,7 @@ import (
) )
func main() { func main() {
link := &List{} link := &piscine.List{}
piscine.ListPushFront(link, "Hello") piscine.ListPushFront(link, "Hello")
piscine.ListPushFront(link, "2") piscine.ListPushFront(link, "2")

65
subjects/listsort.en.md

@ -1,4 +1,4 @@
## listpushback ## listsort
### Instructions ### Instructions
@ -6,19 +6,15 @@ Write a function `ListSort` that sorts the linked list by ascending order.
- This time you only will have the `node` structure. - This time you only will have the `node` structure.
- Try to use recursive.
- Use pointers when ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { type NodeI struct {
data int Data int
next *node Next *NodeI
} }
func ListSort(l *node) *node { func ListSort(l *NodeI) *NodeI {
} }
``` ```
@ -32,53 +28,44 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
//Prints the list func PrintList(l *piscine.NodeI) {
func PrintList(l *node) { it := l
m := l for it != nil {
for m != nil { fmt.Print(it.Data, " -> ")
fmt.Print(m.data, " -> ") it = it.Next
m = m.next
} }
fmt.Print(nil, "\n")
fmt.Print(nil)
fmt.Println()
} }
//insert elements func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI {
func listPushBack(l *node, data int) { n := &piscine.NodeI{Data: data}
n := &node{}
n.data = data
n.next = nil
if l == nil { if l == nil {
l = n return n
return
} }
iterator := l iterator := l
for iterator.next != nil { for iterator.Next != nil {
iterator = iterator.next iterator = iterator.Next
} }
iterator.next = n iterator.Next = n
return l
} }
func main() { func main() {
link := &node{} var link *piscine.NodeI
listPushBack(link, 5) link = listPushBack(link, 5)
listPushBack(link, 4) link = listPushBack(link, 4)
listPushBack(link, 3) link = listPushBack(link, 3)
listPushBack(link, 2) link = listPushBack(link, 2)
listPushBack(link, 1) link = listPushBack(link, 1)
PrintList(piscine.ListSort(link)) PrintList(piscine.ListSort(link))
} }
``` ```
And its output : And its output :
@ -86,6 +73,6 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
0 -> 1 -> 2 -> 3 -> 4 -> 5 -> <nil> 1 -> 2 -> 3 -> 4 -> 5 -> <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

69
subjects/listsort.fr.md

@ -1,44 +1,83 @@
## countif ## listpushback
### Instructions ### Instructions
Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. Write a function `ListSort` that sorts the linked list by ascending order.
### Fonction attendue - This time you only will have the `node` structure.
- Try to use recursive.
- Use pointers when ever you can.
### Expected function and structure
```go ```go
func CountIf(f func(string) bool, tab []string) int { type NodeI struct {
Data int
Next *NodeI
}
func ListSort(l *NodeI) *NodeI {
} }
``` ```
### Utilisation ### Usage
Voici un Ă©ventuel [programme](TODO-LINK) pour tester votre fonction : Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func PrintList(l *piscine.NodeI) {
m := l
for m != nil {
fmt.Print(m.Data, " -> ")
m = m.Next
}
fmt.Print(nil)
fmt.Println()
}
func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI {
n := &piscine.NodeI{Data: data}
if l == nil {
return n
}
iterator := l
for iterator.Next != nil {
iterator = iterator.Next
}
iterator.Next = n
return l
}
func main() { func main() {
tab1 := []string{"Hello", "how", "are", "you"} var link *piscine.NodeI
tab2 := []string{"This","1", "is", "4", "you"}
answer1 := piscine.CountIf(piscine.IsNumeric, tab1) link = listPushBack(link, 5)
answer2 := piscine.CountIf(piscine.IsNumeric, tab2) link = listPushBack(link, 4)
fmt.Println(answer1) link = listPushBack(link, 3)
fmt.Println(answer2) link = listPushBack(link, 2)
link = listPushBack(link, 1)
PrintList(piscine.ListSort(link))
} }
``` ```
Et son résultat : And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
0 1 -> 2 -> 3 -> 4 -> 5 -> <nil>
2
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

10
subjects/max.en.md

@ -23,12 +23,12 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
arrInt := []int{23, 123, 1, 11, 55, 93} arrInt := []int{23, 123, 1, 11, 55, 93}
max := student.Max(arrInt) max := piscine.Max(arrInt)
fmt.Println(max fmt.Println(max
} }
``` ```
@ -36,8 +36,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/max$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/student/max$ ./max student@ubuntu:~/piscine/test$ ./test
123 123
student@ubuntu:~/student/max$ student@ubuntu:~/piscine/test$
``` ```

10
subjects/max.fr.md

@ -23,12 +23,12 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
arrInt := []int{23, 123, 1, 11, 55, 93} arrInt := []int{23, 123, 1, 11, 55, 93}
max := student.Max(arrInt) max := piscine.Max(arrInt)
fmt.Println(max fmt.Println(max
} }
``` ```
@ -36,8 +36,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/max$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/student/max$ ./max student@ubuntu:~/piscine/test$ ./test
123 123
student@ubuntu:~/student/max$ student@ubuntu:~/piscine/test$
``` ```

62
subjects/sortedlistmerge.en.md

@ -1,22 +1,15 @@
## listpushback ## sortedlistmerge
### Instructions ### Instructions
Write a function `SortedListMerge` that mereges two lists, `l1` and `l2`, but it as to join them in ascending order. Write a function `SortedListMerge` that merges two lists, `n1` and `n2`, but it has to join them in ascending order.
- Tip each list as to be already sorted. - Assume that `n1` and `n2` are already sorted
- Use pointers when ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { func SortedListMerge(n1 *NodeI, n2 *NodeI) *NodeI {
data interface{}
next *node
}
func SortedListMerge(l1 *node, l2 *node) *node {
} }
``` ```
@ -30,34 +23,45 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func PrintList(l *list) { func PrintList(l *piscine.NodeI) {
m := l.head it := l
for m != nil { for it != nil {
fmt.Print(m.data, " -> ") fmt.Print(it.Data, " -> ")
m = m.next it = it.Next
} }
fmt.Print(nil, "\n")
}
func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI {
n := &piscine.NodeI{Data: data}
fmt.Print(nil) if l == nil {
fmt.Println() return n
}
iterator := l
for iterator.Next != nil {
iterator = iterator.Next
}
iterator.Next = n
return l
} }
func main() { func main() {
link := &list{} var link *piscine.NodeI
link2 := &list{} var link2 *piscine.NodeI
piscine.ListPushBack(link, "5") link = listPushBack(link, 3)
piscine.ListPushBack(link, "3") link = listPushBack(link, 5)
piscine.ListPushBack(link, "7") link = listPushBack(link, 7)
piscine.ListPushBack(link2, "1") link2 = listPushBack(link2, -2)
piscine.ListPushBack(link2, "-2") link2 = listPushBack(link2, 9)
piscine.ListPushBack(link2, "4")
piscine.ListPushBack(link2, "6")
PrintList(SortedListMerge(link, link2)) PrintList(piscine.SortedListMerge(link2, link))
} }
``` ```
@ -66,6 +70,6 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
-2 -> 0 -> 0 -> 1 -> 3 -> 4 -> 5 -> 6 -> 7 -> <nil> -2 -> 3 -> 5 -> 7 -> 9 -> <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

68
subjects/sortedlistmerge.fr.md

@ -1,44 +1,82 @@
## countif ## sortedlistmerge
### Instructions ### Instructions
Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. Write a function `SortedListMerge` that mereges two lists, `n1` and `n2`, but it as to join them in ascending order.
### Fonction attendue - Tip each list as to be already sorted.
- Use pointers when ever you can.
### Expected function and structure
```go ```go
func CountIf(f func(string) bool, tab []string) int { func SortedListMerge(n1 *NodeI, n2 *NodeI) *NodeI {
} }
``` ```
### Utilisation ### Usage
Voici un Ă©ventuel [programme](TODO-LINK) pour tester votre fonction : Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import ( import (
"fmt" "fmt"
piscine ".." 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
}
fmt.Print(nil)
fmt.Println()
}
func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI {
n := &piscine.NodeI{Data: data}
if l == nil {
return n
}
iterator := l
for iterator.Next != nil {
iterator = iterator.Next
}
iterator.Next = n
return l
}
func main() { func main() {
tab1 := []string{"Hello", "how", "are", "you"} var link *node
tab2 := []string{"This","1", "is", "4", "you"} var link2 *nodes
answer1 := piscine.CountIf(piscine.IsNumeric, tab1)
answer2 := piscine.CountIf(piscine.IsNumeric, tab2) link = listPushBack(link, 5)
fmt.Println(answer1) link = listPushBack(link, 3)
fmt.Println(answer2) link = listPushBack(link, 7)
link2 = listPushBack(link2, -2)
link2 = listPushBack(link2, 4)
PrintList(piscine.SortedListMerge(link2, link))
} }
``` ```
Et son résultat : And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
0 -2 -> 3 -> 4 -> 5 -> 7 -> <nil>
2
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

2
subjects/sortList.fr.md → subjects/sortlist.en.md

@ -1,4 +1,4 @@
## sortList ## sortlist
### Instructions ### Instructions

0
subjects/sortList.en.md → subjects/sortlist.fr.md

66
subjects/sortlistinsert.en.md

@ -1,22 +1,15 @@
## listpushback ## sortlistinsert
### Instructions ### Instructions
Write a function `SortListInsert` that inserts `data_ref` in the linked list, but it as to remain sorted in ascending order. Write a function `SortListInsert` that inserts `data_ref` in the linked list, but keeping the list sorted in ascending order.
- The list as to be alredy sorted. - You can assume that the list passed as an argument is already sorted.
- Use pointers when ever you can.
### Expected function and structure ### Expected function and structure
```go ```go
type node struct { func SortListInsert(l *NodeI, data_ref int) *NodeI{
data int
next *node
}
func SortListInsert(l *node, data_ref int) *node{
} }
``` ```
@ -30,50 +23,47 @@ package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
//Prints the list func PrintList(l *piscine.NodeI) {
func PrintList(l *node) { it := l
m := l for it != nil {
for m != nil { fmt.Print(it.Data, " -> ")
fmt.Print(m.data, " -> ") it = it.Next
m = m.next
} }
fmt.Print(nil) fmt.Print(nil, "\n")
fmt.Println()
} }
//insert elements
func listPushBack(l *node, data int) { func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI {
n := &node{} n := &piscine.NodeI{Data: data}
n.data = data
n.next = nil
if l == nil { if l == nil {
l = n return n
return
} }
iterator := l iterator := l
for iterator.next != nil { for iterator.Next != nil {
iterator = iterator.next iterator = iterator.Next
} }
iterator.next = n iterator.Next = n
return l
} }
func main() { func main() {
link := &node{} var link *piscine.NodeI
listPushBack(link, 1) link = listPushBack(link, 1)
listPushBack(link, 4) link = listPushBack(link, 4)
listPushBack(link, 9) link = listPushBack(link, 9)
PrintList(link) PrintList(link)
link = sortListInsert(link, -2) link = piscine.SortListInsert(link, -2)
link = sortListInsert(link, 2) link = piscine.SortListInsert(link, 2)
PrintList(link) PrintList(link)
} }
``` ```
And its output : And its output :
@ -81,7 +71,7 @@ And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
-2 -> 0 -> 1 -> 2 -> 4 -> 9 -> <nil> 1 -> 4 -> 9 -> <nil>
lee@lee:~/Documents/work/day11/11-16-sortlistinsert/so -2 -> 1 -> 2 -> 4 -> 9 -> <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

66
subjects/sortlistinsert.fr.md

@ -1,44 +1,80 @@
## countif ## sortlistinsert
### Instructions ### Instructions
Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. Write a function `SortListInsert` that inserts `data_ref` in the linked list, but it as to remain sorted in ascending order.
### Fonction attendue - The list as to be alredy sorted.
- Use pointers when ever you can.
### Expected function and structure
```go ```go
func CountIf(f func(string) bool, tab []string) int { func SortListInsert(l *NodeI, data_ref int) *NodeI{
} }
``` ```
### Utilisation ### Usage
Voici un Ă©ventuel [programme](TODO-LINK) pour tester votre fonction : Here is a possible [program](TODO-LINK) to test your function :
```go ```go
package main package main
import ( import (
"fmt" "fmt"
piscine ".." piscine ".."
) )
func PrintList(l *piscine.NodeI) {
m := l
for m != nil {
fmt.Print(m.Data, " -> ")
m = m.Next
}
fmt.Print(nil)
fmt.Println()
}
func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI {
n := &piscine.NodeI{Data: data}
if l == nil {
return n
}
iterator := l
for iterator.Next != nil {
iterator = iterator.Next
}
iterator.Next = n
return l
}
func main() { func main() {
tab1 := []string{"Hello", "how", "are", "you"}
tab2 := []string{"This","1", "is", "4", "you"} var link *piscine.NodeI
answer1 := piscine.CountIf(piscine.IsNumeric, tab1)
answer2 := piscine.CountIf(piscine.IsNumeric, tab2) link = listPushBack(link, 1)
fmt.Println(answer1) link = listPushBack(link, 4)
fmt.Println(answer2) link = listPushBack(link, 9)
PrintList(link)
link = piscine.SortListInsert(link, -2)
link = piscine.SortListInsert(link, 2)
PrintList(link)
} }
``` ```
Et son résultat : And its output :
```console ```console
student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/piscine/test$ ./test student@ubuntu:~/piscine/test$ ./test
0 1 -> 4 -> 9 -> <nil>
2 -2 -> 1 -> 2 -> 4 -> 9 -> <nil>
student@ubuntu:~/piscine/test$ student@ubuntu:~/piscine/test$
``` ```

12
subjects/unmatch.en.md

@ -4,7 +4,7 @@
Write a function, Unmatch, that returns the element of the slice (arr) that does not have a correspondent pair. Write a function, Unmatch, that returns the element of the slice (arr) that does not have a correspondent pair.
The function must have the next signature. - If all the number have a correspondent pair, it shoud return `-1`.
### Expected function ### Expected function
@ -23,12 +23,12 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
arr := []int{1, 2, 3, 1, 2, 3, 4} arr := []int{1, 2, 3, 1, 2, 3, 4}
unmatch := student.Unmatch(arr) unmatch := piscine.Unmatch(arr)
fmt.Println(unmatch) fmt.Println(unmatch)
} }
``` ```
@ -36,8 +36,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/unmatch$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/student/unmatch$ ./unmatch student@ubuntu:~/piscine/test$ ./test
4 4
student@ubuntu:~/student/unmatch$ student@ubuntu:~/piscine/test$
``` ```

12
subjects/unmatch.fr.md

@ -4,8 +4,6 @@
Write a function, Unmatch, that returns the element of the slice (arr) that does not have a correspondent pair. Write a function, Unmatch, that returns the element of the slice (arr) that does not have a correspondent pair.
The function must have the next signature.
### Expected function ### Expected function
```go ```go
@ -23,12 +21,12 @@ package main
import ( import (
"fmt" "fmt"
student ".." piscine ".."
) )
func main() { func main() {
arr := []int{1, 2, 3, 1, 2, 3, 4} arr := []int{1, 2, 3, 1, 2, 3, 4}
unmatch := student.Unmatch(arr) unmatch := piscine.Unmatch(arr)
fmt.Println(unmatch) fmt.Println(unmatch)
} }
``` ```
@ -36,8 +34,8 @@ func main() {
And its output : And its output :
```console ```console
student@ubuntu:~/student/unmatch$ go build student@ubuntu:~/piscine/test$ go build
student@ubuntu:~/student/unmatch$ ./unmatch student@ubuntu:~/piscine/test$ ./test
4 4
student@ubuntu:~/student/unmatch$ student@ubuntu:~/piscine/test$
``` ```

Loading…
Cancel
Save