From d709c6491bfee51f9d51b7d190cf51d74d35bd3b Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 19 Jun 2019 15:14:21 +0100 Subject: [PATCH 01/66] fixi activebits readme from hackaton --- subjects/activebits.en.md | 12 ++++++------ subjects/activebits.fr.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/subjects/activebits.en.md b/subjects/activebits.en.md index 6722ffcc..614186e3 100644 --- a/subjects/activebits.en.md +++ b/subjects/activebits.en.md @@ -2,7 +2,7 @@ ### 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. @@ -23,11 +23,11 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - nbits := student.ActiveBits(7) + nbits := piscine.ActiveBits(7) fmt.Println(nbits) } ``` @@ -35,8 +35,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/activebits$ go build -student@ubuntu:~/student/activebits$ ./activebits +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 10 -student@ubuntu:~/student/activebits$ +student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/activebits.fr.md b/subjects/activebits.fr.md index 6722ffcc..614186e3 100644 --- a/subjects/activebits.fr.md +++ b/subjects/activebits.fr.md @@ -2,7 +2,7 @@ ### 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. @@ -23,11 +23,11 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - nbits := student.ActiveBits(7) + nbits := piscine.ActiveBits(7) fmt.Println(nbits) } ``` @@ -35,8 +35,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/activebits$ go build -student@ubuntu:~/student/activebits$ ./activebits +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 10 -student@ubuntu:~/student/activebits$ +student@ubuntu:~/piscine/test$ ``` From bf3f96d57428f394a07feeb50f8296c34b03d161 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Wed, 19 Jun 2019 15:16:18 +0100 Subject: [PATCH 02/66] Update activebits.en.md --- subjects/activebits.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/activebits.en.md b/subjects/activebits.en.md index 614186e3..fa44a926 100644 --- a/subjects/activebits.en.md +++ b/subjects/activebits.en.md @@ -37,6 +37,6 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -10 +3 student@ubuntu:~/piscine/test$ ``` From 32a8c685fce7f8dc10cc88eae2d2eca6d3053804 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Wed, 19 Jun 2019 15:16:38 +0100 Subject: [PATCH 03/66] Update activebits.fr.md --- subjects/activebits.fr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/activebits.fr.md b/subjects/activebits.fr.md index 614186e3..fa44a926 100644 --- a/subjects/activebits.fr.md +++ b/subjects/activebits.fr.md @@ -37,6 +37,6 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -10 +3 student@ubuntu:~/piscine/test$ ``` From 74e9d6f6f484b66f9ec3e9eebc6e774587d9e85f Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 19 Jun 2019 16:00:57 +0100 Subject: [PATCH 04/66] fix max readme from hackaton --- subjects/max.en.md | 10 +++++----- subjects/max.fr.md | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/subjects/max.en.md b/subjects/max.en.md index 5b664526..a0ef04e8 100644 --- a/subjects/max.en.md +++ b/subjects/max.en.md @@ -23,12 +23,12 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { arrInt := []int{23, 123, 1, 11, 55, 93} - max := student.Max(arrInt) + max := piscine.Max(arrInt) fmt.Println(max } ``` @@ -36,8 +36,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/max$ go build -student@ubuntu:~/student/max$ ./max +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 123 -student@ubuntu:~/student/max$ +student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/max.fr.md b/subjects/max.fr.md index 5b664526..a0ef04e8 100644 --- a/subjects/max.fr.md +++ b/subjects/max.fr.md @@ -23,12 +23,12 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { arrInt := []int{23, 123, 1, 11, 55, 93} - max := student.Max(arrInt) + max := piscine.Max(arrInt) fmt.Println(max } ``` @@ -36,8 +36,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/max$ go build -student@ubuntu:~/student/max$ ./max +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 123 -student@ubuntu:~/student/max$ +student@ubuntu:~/piscine/test$ ``` From b439b5cc23d9c492eb71a9c0742d1fa5f3492bd9 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Wed, 19 Jun 2019 16:25:23 +0100 Subject: [PATCH 05/66] Update activebits.en.md --- subjects/activebits.en.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/subjects/activebits.en.md b/subjects/activebits.en.md index fa44a926..96354229 100644 --- a/subjects/activebits.en.md +++ b/subjects/activebits.en.md @@ -4,8 +4,6 @@ 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 ```go From fa60ce3a096ee3a3c96e4e31ad1b0cd4ba5d2b4f Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Wed, 19 Jun 2019 16:25:37 +0100 Subject: [PATCH 06/66] Update activebits.fr.md --- subjects/activebits.fr.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/subjects/activebits.fr.md b/subjects/activebits.fr.md index fa44a926..96354229 100644 --- a/subjects/activebits.fr.md +++ b/subjects/activebits.fr.md @@ -4,8 +4,6 @@ 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 ```go From 43a58479cf36fa696353bd382943fdd0c69d4c1a Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 19 Jun 2019 18:01:04 +0100 Subject: [PATCH 07/66] fix unmatch readme from hackaton --- subjects/unmatch.en.md | 12 +++++------- subjects/unmatch.fr.md | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/subjects/unmatch.en.md b/subjects/unmatch.en.md index b8ce76e7..afbe285c 100644 --- a/subjects/unmatch.en.md +++ b/subjects/unmatch.en.md @@ -4,8 +4,6 @@ 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 ```go @@ -23,12 +21,12 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { arr := []int{1, 2, 3, 1, 2, 3, 4} - unmatch := student.Unmatch(arr) + unmatch := piscine.Unmatch(arr) fmt.Println(unmatch) } ``` @@ -36,8 +34,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/unmatch$ go build -student@ubuntu:~/student/unmatch$ ./unmatch +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 4 -student@ubuntu:~/student/unmatch$ +student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/unmatch.fr.md b/subjects/unmatch.fr.md index b8ce76e7..afbe285c 100644 --- a/subjects/unmatch.fr.md +++ b/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. -The function must have the next signature. - ### Expected function ```go @@ -23,12 +21,12 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { arr := []int{1, 2, 3, 1, 2, 3, 4} - unmatch := student.Unmatch(arr) + unmatch := piscine.Unmatch(arr) fmt.Println(unmatch) } ``` @@ -36,8 +34,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/unmatch$ go build -student@ubuntu:~/student/unmatch$ ./unmatch +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 4 -student@ubuntu:~/student/unmatch$ +student@ubuntu:~/piscine/test$ ``` From ebdc0e3939cb918f3bf6b9e1093ae039ffe33348 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Wed, 19 Jun 2019 18:04:10 +0100 Subject: [PATCH 08/66] Update unmatch.en.md --- subjects/unmatch.en.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subjects/unmatch.en.md b/subjects/unmatch.en.md index afbe285c..6f3a9c11 100644 --- a/subjects/unmatch.en.md +++ b/subjects/unmatch.en.md @@ -4,6 +4,8 @@ Write a function, Unmatch, that returns the element of the slice (arr) that does not have a correspondent pair. +- If there no number with a correspondent pair, it shoud return `-1`. + ### Expected function ```go From 81520222aecf91fe34d203abad9b625d9ae6fc33 Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 10:23:39 +0100 Subject: [PATCH 09/66] fix listpushback readme --- subjects/listpushback.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listpushback.en.md b/subjects/listpushback.en.md index eada7bf9..8bc83d9d 100644 --- a/subjects/listpushback.en.md +++ b/subjects/listpushback.en.md @@ -35,7 +35,7 @@ import ( func main() { - link := &List{} + link := &piscine.List{} piscine.ListPushBack(link, "Hello") piscine.ListPushBack(link, "man") From c2ebaccdda3af994c67a7bb8e84063737655676e Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 11:13:17 +0100 Subject: [PATCH 10/66] fix some sintax errors in the readme proposed function and program --- subjects/listpushfront.en.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/subjects/listpushfront.en.md b/subjects/listpushfront.en.md index 0e1e511b..288e51b7 100644 --- a/subjects/listpushfront.en.md +++ b/subjects/listpushfront.en.md @@ -17,7 +17,7 @@ type List struct { Tail *Node } -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 import ( - "fmt" piscine ".." + "fmt" ) func main() { - link := &list{} + link := &piscine.List{} piscine.ListPushFront(link, "Hello") piscine.ListPushFront(link, "man") piscine.ListPushFront(link, "how are you") - for link.head != nil { - fmt.Println(link.head.data) - link.head = link.head.next + it := link.Head + for it != nil { + fmt.Println(it.Data) + it = it.Next } } ``` From dd06dd22aab92d6726bf337dff0d920619e36f94 Mon Sep 17 00:00:00 2001 From: lee Date: Fri, 21 Jun 2019 12:11:31 +0100 Subject: [PATCH 11/66] fix readme btreeinsertdata quest12 imports --- subjects/btreeinsertdata.en.md | 13 +++++++++---- subjects/btreeinsertdata.fr.md | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/subjects/btreeinsertdata.en.md b/subjects/btreeinsertdata.en.md index ff319c89..27a212d8 100644 --- a/subjects/btreeinsertdata.en.md +++ b/subjects/btreeinsertdata.en.md @@ -26,11 +26,16 @@ Here is a possible [program](TODO-LINK) to test your function : ```go package main +import ( + "fmt" + piscine ".." +) + func main() { - root := &TreeNode{data: "4"} - BTreeInsertData(root, "1") - BTreeInsertData(root, "7") - BTreeInsertData(root, "5") + root := &piscine.TreeNode{data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") fmt.Println(root.left.data) fmt.Println(root.data) fmt.Println(root.right.left.data) diff --git a/subjects/btreeinsertdata.fr.md b/subjects/btreeinsertdata.fr.md index ff319c89..27a212d8 100644 --- a/subjects/btreeinsertdata.fr.md +++ b/subjects/btreeinsertdata.fr.md @@ -26,11 +26,16 @@ Here is a possible [program](TODO-LINK) to test your function : ```go package main +import ( + "fmt" + piscine ".." +) + func main() { - root := &TreeNode{data: "4"} - BTreeInsertData(root, "1") - BTreeInsertData(root, "7") - BTreeInsertData(root, "5") + root := &piscine.TreeNode{data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") fmt.Println(root.left.data) fmt.Println(root.data) fmt.Println(root.right.left.data) From e26e3ce2525070e94dea0d422a75153694871d25 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Fri, 21 Jun 2019 12:36:42 +0100 Subject: [PATCH 12/66] Update btreeinsertdata.en.md --- subjects/btreeinsertdata.en.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subjects/btreeinsertdata.en.md b/subjects/btreeinsertdata.en.md index 27a212d8..2125affc 100644 --- a/subjects/btreeinsertdata.en.md +++ b/subjects/btreeinsertdata.en.md @@ -32,14 +32,14 @@ import ( ) func main() { - root := &piscine.TreeNode{data: "4"} + root := &piscine.TreeNode{Data: "4"} piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - fmt.Println(root.left.data) - fmt.Println(root.data) - fmt.Println(root.right.left.data) - fmt.Println(root.right.data) + fmt.Println(root.Left.Data) + fmt.Println(root.Data) + fmt.Println(root.Right.Left.Data) + fmt.Println(root.Right.Data) } ``` From 50499a99a67d0267a11a23f6475e79cd76be2877 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Fri, 21 Jun 2019 12:36:59 +0100 Subject: [PATCH 13/66] Update btreeinsertdata.fr.md --- subjects/btreeinsertdata.fr.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subjects/btreeinsertdata.fr.md b/subjects/btreeinsertdata.fr.md index 27a212d8..2125affc 100644 --- a/subjects/btreeinsertdata.fr.md +++ b/subjects/btreeinsertdata.fr.md @@ -32,14 +32,14 @@ import ( ) func main() { - root := &piscine.TreeNode{data: "4"} + root := &piscine.TreeNode{Data: "4"} piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - fmt.Println(root.left.data) - fmt.Println(root.data) - fmt.Println(root.right.left.data) - fmt.Println(root.right.data) + fmt.Println(root.Left.Data) + fmt.Println(root.Data) + fmt.Println(root.Right.Left.Data) + fmt.Println(root.Right.Data) } ``` From b9a2ad00fc4de53ee55a50962bb99577cf7c8a8e Mon Sep 17 00:00:00 2001 From: lee Date: Fri, 21 Jun 2019 14:00:28 +0100 Subject: [PATCH 14/66] fix readme BtreeApllyInOrder --- subjects/btreeapplyinorder.en.md | 12 ++++++------ subjects/btreeapplyinorder.fr.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/subjects/btreeapplyinorder.en.md b/subjects/btreeapplyinorder.en.md index 25cc36a9..e182df07 100644 --- a/subjects/btreeapplyinorder.en.md +++ b/subjects/btreeapplyinorder.en.md @@ -8,7 +8,7 @@ Write a function that applies a function in order to each element in the tree ### Expected function ```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 ( "fmt" - piscine "." + piscine ".." ) func main() { @@ -30,7 +30,7 @@ func main() { piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - BTreeApplyInorder(root, fmt.Println) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` @@ -38,11 +38,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreeinsertdata$ go build -student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 1 4 5 7 -student@ubuntu:~/piscine/btreeinsertdata$ +student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/btreeapplyinorder.fr.md b/subjects/btreeapplyinorder.fr.md index 25cc36a9..e182df07 100644 --- a/subjects/btreeapplyinorder.fr.md +++ b/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 ```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 ( "fmt" - piscine "." + piscine ".." ) func main() { @@ -30,7 +30,7 @@ func main() { piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - BTreeApplyInorder(root, fmt.Println) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` @@ -38,11 +38,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreeinsertdata$ go build -student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 1 4 5 7 -student@ubuntu:~/piscine/btreeinsertdata$ +student@ubuntu:~/piscine/test$ ``` From 1fa3e3e486eea8a81f332daca605ba1ba777d86e Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 14:12:23 +0100 Subject: [PATCH 15/66] fix sintax error --- subjects/listsize.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listsize.en.md b/subjects/listsize.en.md index c69f59f8..1c076c40 100644 --- a/subjects/listsize.en.md +++ b/subjects/listsize.en.md @@ -35,7 +35,7 @@ import ( ) func main() { - link := &List{} + link := &piscine.List{} piscine.ListPushFront(link, "Hello") piscine.ListPushFront(link, "2") From 9bede6f8ed2a8c12bff6675b439d010b65af481a Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 15:57:54 +0100 Subject: [PATCH 16/66] changed type Node to NodeL --- subjects/listsize.en.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subjects/listsize.en.md b/subjects/listsize.en.md index 1c076c40..da623774 100644 --- a/subjects/listsize.en.md +++ b/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 ```go -type Node struct { +type NodeL struct { Data interface{} - Next *Node + Next *NodeL } type List struct { - Head *Node - Tail *Node + Head *NodeL + Tail *NodeL } func ListSize(l *List) int { From a36cac71759b2d145b7d61fb1a3be1fabdcc7f43 Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 16:02:03 +0100 Subject: [PATCH 17/66] change type Node to NodeL --- subjects/listpushfront.en.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subjects/listpushfront.en.md b/subjects/listpushfront.en.md index 288e51b7..35901b23 100644 --- a/subjects/listpushfront.en.md +++ b/subjects/listpushfront.en.md @@ -7,14 +7,14 @@ Write a function `ListPushBack` that inserts a new element `node` at the beginni ### Expected function and structure ```go -type Node struct { +type NodeL struct { Data interface{} - Next *Node + Next *NodeL } type List struct { - Head *Node - Tail *Node + Head *NodeL + Tail *NodeL } func ListPushFront(l *List, data interface{}) { From dd231d653e73590f05458f95589c1e57585e0af0 Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 16:03:38 +0100 Subject: [PATCH 18/66] change type Node to NodeL --- subjects/listpushback.en.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subjects/listpushback.en.md b/subjects/listpushback.en.md index 8bc83d9d..45fa4d64 100644 --- a/subjects/listpushback.en.md +++ b/subjects/listpushback.en.md @@ -2,19 +2,19 @@ ### 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 ```go -type Node struct { +type NodeL struct { Data interface{} - Next *Node + Next *NodeL } type List struct { - Head *Node - Tail *Node + Head *NodeL + Tail *NodeL } func ListPushBack(l *List, data interface{}) { From 103d9d6245cce0d468d7f950e480ead3d483b6f6 Mon Sep 17 00:00:00 2001 From: Christopher Fremond Date: Fri, 21 Jun 2019 19:02:55 +0100 Subject: [PATCH 19/66] cpmpact modif --- subjects/compact.en.md | 2 +- subjects/compact.fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 3c82da60..29184b97 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -4,7 +4,7 @@ Write a function `Compact` that takes a pointer to an array as parameter and overwrites the elements that points to `nil`. -- Hint: This fonction exists in Ruby. +- Hint : This fonction exists in Ruby. ### Expected function diff --git a/subjects/compact.fr.md b/subjects/compact.fr.md index b2a50fc8..ed9c3efb 100644 --- a/subjects/compact.fr.md +++ b/subjects/compact.fr.md @@ -4,7 +4,7 @@ É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`. -- Indice: Cette fonction existe in Ruby. +- Indice : Cette fonction existe in Ruby. ### Fonction attendue From 79e6a7709b03b44c763d4a29a8e2991ab64e739f Mon Sep 17 00:00:00 2001 From: Christopher Fremond Date: Fri, 21 Jun 2019 19:12:40 +0100 Subject: [PATCH 20/66] fix of compact --- subjects/compact.en.md | 48 +++++++++++++++++++++++++++++++++--------- subjects/compact.fr.md | 44 +++++++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 18 deletions(-) diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 29184b97..5c637f85 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -1,15 +1,18 @@ -## compact +## Compact ### 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 -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 package main -import fmt +import ( + "fmt" + + piscine ".." +) + +const N = 6 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(Compact(ptr, len(array))) + fmt.Println("Size after compacting:", piscine.Compact(&arr)) + + for _, v := range arr { + fmt.Println(v) + } } ``` @@ -36,6 +55,15 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -3 +a + +b + +c + +Size after compacting: 3 +a +b +c student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/compact.fr.md b/subjects/compact.fr.md index ed9c3efb..aaeb5b8e 100644 --- a/subjects/compact.fr.md +++ b/subjects/compact.fr.md @@ -2,14 +2,17 @@ ### 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 ```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 package main -import fmt +import ( + "fmt" + + piscine ".." +) + +const N = 6 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(Compact(ptr, len(array))) + fmt.Println("Size after compacting:", piscine.Compact(&arr)) + + for _, v := range arr { + fmt.Println(v) + } } ``` @@ -36,6 +55,15 @@ Et son résultat : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -3 +a + +b + +c + +Size after compacting: 3 +a +b +c student@ubuntu:~/piscine/test$ ``` From d8a7cb35bd612940775f6d3d18862da94de35b9f Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 24 Jun 2019 10:21:45 +0100 Subject: [PATCH 21/66] fix the readme btreeapplypreorder from quest 12 --- subjects/btreeapplypreorder.en.md | 14 +++++++------- subjects/btreeapplypreorder.fr.md | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/subjects/btreeapplypreorder.en.md b/subjects/btreeapplypreorder.en.md index bbc17b7a..4a43b56a 100644 --- a/subjects/btreeapplypreorder.en.md +++ b/subjects/btreeapplypreorder.en.md @@ -7,7 +7,7 @@ Write a function that applies a function using a preorder walk to each element i ### Expected function ```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 import ( - "fmt" - piscine "." + "fmt" + piscine ".." ) func main() { @@ -29,7 +29,7 @@ func main() { piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - BTreeApplyPreorder(root, fmt.Println) + piscine.BTreeApplyPreorder(root, fmt.Println) } ``` @@ -37,11 +37,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreeinsertdata$ go build -student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 4 1 7 5 -student@ubuntu:~/piscine/btreeinsertdata$ +student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/btreeapplypreorder.fr.md b/subjects/btreeapplypreorder.fr.md index bbc17b7a..4a43b56a 100644 --- a/subjects/btreeapplypreorder.fr.md +++ b/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 ```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 import ( - "fmt" - piscine "." + "fmt" + piscine ".." ) func main() { @@ -29,7 +29,7 @@ func main() { piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - BTreeApplyPreorder(root, fmt.Println) + piscine.BTreeApplyPreorder(root, fmt.Println) } ``` @@ -37,11 +37,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreeinsertdata$ go build -student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 4 1 7 5 -student@ubuntu:~/piscine/btreeinsertdata$ +student@ubuntu:~/piscine/test$ ``` From b86582a4df7ce188df74fcfff9ee0967505fea5d Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 24 Jun 2019 11:56:06 +0100 Subject: [PATCH 22/66] fix readme btreesearchitem from quest 12 --- subjects/btreesearchitem.en.md | 23 +++++++++++------------ subjects/btreesearchitem.fr.md | 23 +++++++++++------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/subjects/btreesearchitem.en.md b/subjects/btreesearchitem.en.md index abe4491e..2367eead 100644 --- a/subjects/btreesearchitem.en.md +++ b/subjects/btreesearchitem.en.md @@ -7,10 +7,9 @@ Write a function that searches for an item with a data element equal to elem and ### Expected function ```go -func BTreeSearchItem(root *piscine_test.TreeNode, elem string) *piscine_test.TreeNode { +func BTreeSearchItem(root *TreeNode, elem string) *TreeNode { } - ``` ### Usage @@ -21,16 +20,16 @@ Here is a possible [program](TODO-LINK) to test your function : package main import ( - "fmt" - piscine "." + "fmt" + piscine ".." ) func main() { - root := &piscine_test.TreeNode{Data: "4"} - piscine_test.BTreeInsertData(root, "1") - piscine_test.BTreeInsertData(root, "7") - piscine_test.BTreeInsertData(root, "5") - selected := BTreeSearchItem(root, "7") + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + selected := piscine.BTreeSearchItem(root, "7") fmt.Print("Item selected -> ") if selected != nil { fmt.Println(selected.Data) @@ -64,11 +63,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreesearchitem$ go build -student@ubuntu:~/piscine/btreesearchitem$ ./btreesearchitem +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test Item selected -> 7 Parent of selected item -> 4 Left child of selected item -> 5 Right child of selected item -> nil -student@ubuntu:~/piscine/btreesearchitem$ +student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/btreesearchitem.fr.md b/subjects/btreesearchitem.fr.md index abe4491e..2367eead 100644 --- a/subjects/btreesearchitem.fr.md +++ b/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 ```go -func BTreeSearchItem(root *piscine_test.TreeNode, elem string) *piscine_test.TreeNode { +func BTreeSearchItem(root *TreeNode, elem string) *TreeNode { } - ``` ### Usage @@ -21,16 +20,16 @@ Here is a possible [program](TODO-LINK) to test your function : package main import ( - "fmt" - piscine "." + "fmt" + piscine ".." ) func main() { - root := &piscine_test.TreeNode{Data: "4"} - piscine_test.BTreeInsertData(root, "1") - piscine_test.BTreeInsertData(root, "7") - piscine_test.BTreeInsertData(root, "5") - selected := BTreeSearchItem(root, "7") + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + selected := piscine.BTreeSearchItem(root, "7") fmt.Print("Item selected -> ") if selected != nil { fmt.Println(selected.Data) @@ -64,11 +63,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreesearchitem$ go build -student@ubuntu:~/piscine/btreesearchitem$ ./btreesearchitem +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test Item selected -> 7 Parent of selected item -> 4 Left child of selected item -> 5 Right child of selected item -> nil -student@ubuntu:~/piscine/btreesearchitem$ +student@ubuntu:~/piscine/test$ ``` From dc2ae91b9b36c31586236acdc9eb4e6335313049 Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 24 Jun 2019 12:34:10 +0100 Subject: [PATCH 23/66] fix readme listlast from quest11 --- subjects/listlast.en.md | 14 ++++++------- subjects/listlast.fr.md | 45 +++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/subjects/listlast.en.md b/subjects/listlast.en.md index 24503898..273d3ef6 100644 --- a/subjects/listlast.en.md +++ b/subjects/listlast.en.md @@ -17,7 +17,7 @@ type List struct { Tail *Node } -func ListLast(l *list) *list { +func ListLast(l *List) *List { } ``` @@ -30,20 +30,20 @@ package main import ( "fmt" + piscine ".." ) - func main() { - link := &list{} - link2 := &list{} + link := &piscine.List{} + link2 := &piscine.List{} piscine.ListPushBack(link, "three") piscine.ListPushBack(link, 3) piscine.ListPushBack(link, "1") - fmt.Println(piscine.ListLast(link).head) - fmt.Println(piscine.ListLast(link2).head) + fmt.Println(piscine.ListLast(link)) + fmt.Println(piscine.ListLast(link2)) } ``` @@ -53,7 +53,7 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -&{1 } +1 student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listlast.fr.md b/subjects/listlast.fr.md index 7db913a6..273d3ef6 100644 --- a/subjects/listlast.fr.md +++ b/subjects/listlast.fr.md @@ -1,44 +1,59 @@ -## 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`. +Write a function `ListLast` that returns the last element of the linked list. -### Fonction attendue +### Expected function and structure ```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) *List { } ``` -### Utilisation +### Usage -Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : +Here is a possible [program](TODO-LINK) to test your function : ```go package main import ( "fmt" + piscine ".." ) 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, "three") + piscine.ListPushBack(link, 3) + piscine.ListPushBack(link, "1") + + fmt.Println(piscine.ListLast(link)) + fmt.Println(piscine.ListLast(link2)) } + ``` -Et son résultat : +And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +1 + student@ubuntu:~/piscine/test$ ``` From 0048dbd74fd072fab044c6bfd6249d68763b830c Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Mon, 24 Jun 2019 12:46:15 +0100 Subject: [PATCH 24/66] Update listlast.en.md --- subjects/listlast.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listlast.en.md b/subjects/listlast.en.md index 273d3ef6..e46d0aa8 100644 --- a/subjects/listlast.en.md +++ b/subjects/listlast.en.md @@ -17,7 +17,7 @@ type List struct { Tail *Node } -func ListLast(l *List) *List { +func ListLast(l *List) interface{} { } ``` From a24878eea139c3370ad290cda3f6e7e52bfd9347 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Mon, 24 Jun 2019 12:46:52 +0100 Subject: [PATCH 25/66] Update listlast.fr.md --- subjects/listlast.fr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listlast.fr.md b/subjects/listlast.fr.md index 273d3ef6..e46d0aa8 100644 --- a/subjects/listlast.fr.md +++ b/subjects/listlast.fr.md @@ -17,7 +17,7 @@ type List struct { Tail *Node } -func ListLast(l *List) *List { +func ListLast(l *List) interface{} { } ``` From 4887f2a04e391961c5e0ab6143e0cb24a3857cfe Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 24 Jun 2019 14:52:45 +0100 Subject: [PATCH 26/66] fix readme listclear from quest 11 --- subjects/listclear.en.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/subjects/listclear.en.md b/subjects/listclear.en.md index 0da3b3c9..4606a86e 100644 --- a/subjects/listclear.en.md +++ b/subjects/listclear.en.md @@ -9,18 +9,7 @@ Write a function `ListClear` that delets all `nodes` from a linked list, deletin ### Expected function and structure ```go -type Node struct { - Data interface{} - Next *Node -} - -type List struct { - Head *Node - Tail *Node -} - func ListClear(l *List) { - } ``` @@ -33,11 +22,12 @@ package main import ( "fmt" + piscine ".." ) type List = piscine.List -type Node = piscine.Node +type Node = piscine.NodeL func PrintList(l *List) { link := l.Head @@ -65,6 +55,7 @@ func main() { ``` + And its output : ```console From b897615c127e46462b1ce52b5df553c22ae3d2fd Mon Sep 17 00:00:00 2001 From: augusto-mantilla Date: Mon, 24 Jun 2019 16:49:48 +0100 Subject: [PATCH 27/66] update unmatch --- subjects/unmatch.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/unmatch.en.md b/subjects/unmatch.en.md index 6f3a9c11..13dd0fe7 100644 --- a/subjects/unmatch.en.md +++ b/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. -- If there no number with a correspondent pair, it shoud return `-1`. +- If all the number have a correspondent pair, it shoud return `-1`. ### Expected function From ebbda76a9b1c1bd25eef79117f4765f73d5095c3 Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 24 Jun 2019 17:46:39 +0100 Subject: [PATCH 28/66] fix readme from btreelevelcount from quest 12 --- subjects/btreelevelcount.en.md | 21 +++++++++++---------- subjects/btreelevelcount.fr.md | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/subjects/btreelevelcount.en.md b/subjects/btreelevelcount.en.md index 2576e109..ef9c7806 100644 --- a/subjects/btreelevelcount.en.md +++ b/subjects/btreelevelcount.en.md @@ -7,7 +7,7 @@ Write a function, BTreeLevelCount, that return the number of levels of the tree ### Expected function ```go -func BTreeLevelCount(root *piscine.TreeNode) int { +func BTreeLevelCount(root *TreeNode) int { } ``` @@ -21,23 +21,24 @@ package main import ( "fmt" - student ".." + + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - fmt.Println(BTreeLevelCount(root)) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + fmt.Println(piscine.BTreeLevelCount(root)) } ``` And its output : ```console -student@ubuntu:~/student/btreesearchitem$ go build -student@ubuntu:~/student/btreesearchitem$ ./btreesearchitem +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 3 -student@ubuntu:~/student/btreesearchitem$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreelevelcount.fr.md b/subjects/btreelevelcount.fr.md index 2576e109..ef9c7806 100644 --- a/subjects/btreelevelcount.fr.md +++ b/subjects/btreelevelcount.fr.md @@ -7,7 +7,7 @@ Write a function, BTreeLevelCount, that return the number of levels of the tree ### Expected function ```go -func BTreeLevelCount(root *piscine.TreeNode) int { +func BTreeLevelCount(root *TreeNode) int { } ``` @@ -21,23 +21,24 @@ package main import ( "fmt" - student ".." + + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - fmt.Println(BTreeLevelCount(root)) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + fmt.Println(piscine.BTreeLevelCount(root)) } ``` And its output : ```console -student@ubuntu:~/student/btreesearchitem$ go build -student@ubuntu:~/student/btreesearchitem$ ./btreesearchitem +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 3 -student@ubuntu:~/student/btreesearchitem$ +student@ubuntu:~/student/test$ ``` From 845df1dc0d22425859f593405db9016253ad08a8 Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 10:46:24 +0100 Subject: [PATCH 29/66] fix some typo --- subjects/listclear.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listclear.en.md b/subjects/listclear.en.md index 4606a86e..537abebc 100644 --- a/subjects/listclear.en.md +++ b/subjects/listclear.en.md @@ -2,7 +2,7 @@ ### 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 From 525d91717ac8a74964c1bc1bd554b32b8a8c4547 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 11:27:08 +0100 Subject: [PATCH 30/66] fix readme btreeisbinary from quest 12 --- subjects/btreeisbinary.en.md | 18 +++++++++--------- subjects/btreeisbinary.fr.md | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/subjects/btreeisbinary.en.md b/subjects/btreeisbinary.en.md index e57a11a9..2a93d314 100644 --- a/subjects/btreeisbinary.en.md +++ b/subjects/btreeisbinary.en.md @@ -23,23 +23,23 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - fmt.Println(student.BTreeIsBinary(root)) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + fmt.Println(piscine.BTreeIsBinary(root)) } ``` And its output : ```console -student@ubuntu:~/student/btreeisbinary$ go build -student@ubuntu:~/student/btreeisbinary$ ./btreeisbinary +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test true -student@ubuntu:~/student/btreeisbinary$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreeisbinary.fr.md b/subjects/btreeisbinary.fr.md index e57a11a9..2a93d314 100644 --- a/subjects/btreeisbinary.fr.md +++ b/subjects/btreeisbinary.fr.md @@ -23,23 +23,23 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - fmt.Println(student.BTreeIsBinary(root)) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + fmt.Println(piscine.BTreeIsBinary(root)) } ``` And its output : ```console -student@ubuntu:~/student/btreeisbinary$ go build -student@ubuntu:~/student/btreeisbinary$ ./btreeisbinary +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test true -student@ubuntu:~/student/btreeisbinary$ +student@ubuntu:~/student/test$ ``` From 066769728bc6bbf260e064f64556135a0d923409 Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 12:29:06 +0100 Subject: [PATCH 31/66] fix some sintax erros in listat readme --- subjects/listat.en.md | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/subjects/listat.en.md b/subjects/listat.en.md index 4518a82d..3a6a650a 100644 --- a/subjects/listat.en.md +++ b/subjects/listat.en.md @@ -2,20 +2,20 @@ ### 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` ### Expected function and structure ```go -type Node struct { +type NodeL struct { 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() { - link := &Node{} + link := &piscine.List{} - ListPushBack(link, "hello") - ListPushBack(link, "how are") - ListPushBack(link, "you") - ListPushBack(link, 1) + piscine.ListPushBack(link, "hello") + piscine.ListPushBack(link, "how are") + piscine.ListPushBack(link, "you") + piscine.ListPushBack(link, 1) - fmt.Println() - - fmt.Println(ListAt(link, 3).Data) - fmt.Println(ListAt(link, 1).Data) - fmt.Println(ListAt(link, 7)) + fmt.Println(piscine.ListAt(link.Head, 3).Data) + fmt.Println(piscine.ListAt(link.Head, 1).Data) + fmt.Println(piscine.ListAt(link.Head, 7)) } ``` @@ -54,8 +52,8 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -you -hello +1 +how are student@ubuntu:~/piscine/test$ -``` +``` \ No newline at end of file From c4ab04db9c5649c3af4b4ae6afd8b9b4906fe9cc Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 12:44:10 +0100 Subject: [PATCH 32/66] raeame btreeapplybylevel from quest 12 --- subjects/btreeapplybylevel.en.md | 20 ++++++++++---------- subjects/btreeapplybylevel.fr.md | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/subjects/btreeapplybylevel.en.md b/subjects/btreeapplybylevel.en.md index 85cd3eb0..e964f86a 100644 --- a/subjects/btreeapplybylevel.en.md +++ b/subjects/btreeapplybylevel.en.md @@ -2,7 +2,7 @@ ### 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. @@ -23,26 +23,26 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - student.BTreeApplyByLevel(root, fmt.Println) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + piscine.BTreeApplyByLevel(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreeapplybylevel$ go build -student@ubuntu:~/student/btreeapplybylevel$ ./btreeapplybylevel +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 4 1 7 5 -student@ubuntu:~/student/btreeapplybylevel$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreeapplybylevel.fr.md b/subjects/btreeapplybylevel.fr.md index 85cd3eb0..e964f86a 100644 --- a/subjects/btreeapplybylevel.fr.md +++ b/subjects/btreeapplybylevel.fr.md @@ -2,7 +2,7 @@ ### 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. @@ -23,26 +23,26 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - student.BTreeApplyByLevel(root, fmt.Println) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + piscine.BTreeApplyByLevel(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreeapplybylevel$ go build -student@ubuntu:~/student/btreeapplybylevel$ ./btreeapplybylevel +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 4 1 7 5 -student@ubuntu:~/student/btreeapplybylevel$ +student@ubuntu:~/student/test$ ``` From dfae81bbd1571d857bcd571deff4484bd1ad3b6e Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 13:43:27 +0100 Subject: [PATCH 33/66] readme btreemax from quest 12 --- subjects/btreemax.en.md | 21 +++++++++++---------- subjects/btreemax.fr.md | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/subjects/btreemax.en.md b/subjects/btreemax.en.md index dc389960..3fa2bc5c 100644 --- a/subjects/btreemax.en.md +++ b/subjects/btreemax.en.md @@ -2,7 +2,7 @@ ### 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. @@ -23,15 +23,16 @@ package main import ( "fmt" - student ".." + + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - max := student.BTreeMax(root) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + max := piscine.BTreeMax(root) fmt.Println(max.Data) } ``` @@ -39,8 +40,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/btreemax$ go build -student@ubuntu:~/student/btreemax$ ./btreemax +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 7 -student@ubuntu:~/student/btreemax$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreemax.fr.md b/subjects/btreemax.fr.md index dc389960..3fa2bc5c 100644 --- a/subjects/btreemax.fr.md +++ b/subjects/btreemax.fr.md @@ -2,7 +2,7 @@ ### 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. @@ -23,15 +23,16 @@ package main import ( "fmt" - student ".." + + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - max := student.BTreeMax(root) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + max := piscine.BTreeMax(root) fmt.Println(max.Data) } ``` @@ -39,8 +40,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/btreemax$ go build -student@ubuntu:~/student/btreemax$ ./btreemax +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 7 -student@ubuntu:~/student/btreemax$ +student@ubuntu:~/student/test$ ``` From 1701eb3228657b01f4d89a304384818fc5e166d3 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 14:13:54 +0100 Subject: [PATCH 34/66] readme btreemin from quest 12 --- subjects/btreemin.en.md | 21 +++++++++++---------- subjects/btreemin.fr.md | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/subjects/btreemin.en.md b/subjects/btreemin.en.md index f3471856..8de2f9a0 100644 --- a/subjects/btreemin.en.md +++ b/subjects/btreemin.en.md @@ -2,7 +2,7 @@ ### 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. @@ -23,15 +23,16 @@ package main import ( "fmt" - student ".." + + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - min := student.BTreeMin(root) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + min := piscine.BTreeMin(root) fmt.Println(min.Data) } ``` @@ -39,8 +40,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/btreemin$ go build -student@ubuntu:~/student/btreemin$ ./btreemin +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 1 -student@ubuntu:~/student/btreemin$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreemin.fr.md b/subjects/btreemin.fr.md index f3471856..8de2f9a0 100644 --- a/subjects/btreemin.fr.md +++ b/subjects/btreemin.fr.md @@ -2,7 +2,7 @@ ### 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. @@ -23,15 +23,16 @@ package main import ( "fmt" - student ".." + + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - min := student.BTreeMin(root) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + min := piscine.BTreeMin(root) fmt.Println(min.Data) } ``` @@ -39,8 +40,8 @@ func main() { And its output : ```console -student@ubuntu:~/student/btreemin$ go build -student@ubuntu:~/student/btreemin$ ./btreemin +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 1 -student@ubuntu:~/student/btreemin$ +student@ubuntu:~/student/test$ ``` From 1b662f52d82f5e46e09da6e92568edc141501092 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 14:48:14 +0100 Subject: [PATCH 35/66] readme btreetransplant from quest 12 --- subjects/btreetransplant.en.md | 26 +++++++++++++------------- subjects/btreetransplant.fr.md | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/subjects/btreetransplant.en.md b/subjects/btreetransplant.en.md index e8093914..0e8438a7 100644 --- a/subjects/btreetransplant.en.md +++ b/subjects/btreetransplant.en.md @@ -2,7 +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. +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. @@ -23,29 +23,29 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "1") - replacement := &student.TreeNode{Data: "3"} - root = student.BTreeTransplant(root, node, replacement) - student.BTreeApplyInorder(root, fmt.Println) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "1") + replacement := &piscine.TreeNode{Data: "3"} + root = piscine.BTreeTransplant(root, node, replacement) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreetransplant$ go build -student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 3 4 5 7 -student@ubuntu:~/student/btreetrandsplant$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreetransplant.fr.md b/subjects/btreetransplant.fr.md index e8093914..0e8438a7 100644 --- a/subjects/btreetransplant.fr.md +++ b/subjects/btreetransplant.fr.md @@ -2,7 +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. +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. @@ -23,29 +23,29 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "1") - replacement := &student.TreeNode{Data: "3"} - root = student.BTreeTransplant(root, node, replacement) - student.BTreeApplyInorder(root, fmt.Println) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "1") + replacement := &piscine.TreeNode{Data: "3"} + root = piscine.BTreeTransplant(root, node, replacement) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreetransplant$ go build -student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 3 4 5 7 -student@ubuntu:~/student/btreetrandsplant$ +student@ubuntu:~/student/test$ ``` From e399675dd0af7e89648e0170e18391565702b99e Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 14:54:31 +0100 Subject: [PATCH 36/66] fix sintax error in listreverse --- subjects/listreverse.en.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/subjects/listreverse.en.md b/subjects/listreverse.en.md index a602a052..bbe15d79 100644 --- a/subjects/listreverse.en.md +++ b/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 ```go -type node struct { - data interface{} - next *node +type NodeL struct { + Data interface{} + Next *NodeL } -type list struct { - head *node - tail *node +type List struct { + Head *NodeL + Tail *NodeL } -func ListReverse(l *list) { +func ListReverse(l *List) { } ``` @@ -36,18 +36,18 @@ import ( ) func main() { - link := &list{} + link := &piscine.List{} - listPushBack(link, 1) - listPushBack(link, 2) - listPushBack(link, 3) - listPushBack(link, 4) + piscine.ListPushBack(link, 1) + piscine.ListPushBack(link, 2) + piscine.ListPushBack(link, 3) + piscine.ListPushBack(link, 4) - listReverse(link) + piscine.ListReverse(link) - for link.head != nil { - fmt.Println(link.head.data) - link.head = link.head.next + for link.Head != nil { + fmt.Println(link.Head.Data) + link.Head = link.Head.Next } } ``` From caa5aa613dc5a10f50bc784dd0b85bf6f6258986 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 15:11:33 +0100 Subject: [PATCH 37/66] readme btreetransplant from quest 12 --- subjects/btreetransplant.en.md | 26 +++++++++++++------------- subjects/btreetransplant.fr.md | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/subjects/btreetransplant.en.md b/subjects/btreetransplant.en.md index e8093914..50beed3a 100644 --- a/subjects/btreetransplant.en.md +++ b/subjects/btreetransplant.en.md @@ -2,7 +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. +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. @@ -23,29 +23,29 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "1") - replacement := &student.TreeNode{Data: "3"} - root = student.BTreeTransplant(root, node, replacement) - student.BTreeApplyInorder(root, fmt.Println) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "1") + replacement := &piscine.TreeNode{Data: "3"} + root = piscine.BTreeTransplant(root, node, replacement) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreetransplant$ go build -student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 3 4 5 7 -student@ubuntu:~/student/btreetrandsplant$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreetransplant.fr.md b/subjects/btreetransplant.fr.md index e8093914..50beed3a 100644 --- a/subjects/btreetransplant.fr.md +++ b/subjects/btreetransplant.fr.md @@ -2,7 +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. +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. @@ -23,29 +23,29 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "1") - replacement := &student.TreeNode{Data: "3"} - root = student.BTreeTransplant(root, node, replacement) - student.BTreeApplyInorder(root, fmt.Println) + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "1") + replacement := &piscine.TreeNode{Data: "3"} + root = piscine.BTreeTransplant(root, node, replacement) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreetransplant$ go build -student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test 3 4 5 7 -student@ubuntu:~/student/btreetrandsplant$ +student@ubuntu:~/student/test$ ``` From 0c3454c9f9eb0f3033fff0cc477a0211b2c4007b Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 16:59:06 +0100 Subject: [PATCH 38/66] add test for the head and tail in the readme of listreverse --- subjects/listreverse.en.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/subjects/listreverse.en.md b/subjects/listreverse.en.md index bbe15d79..f661ef47 100644 --- a/subjects/listreverse.en.md +++ b/subjects/listreverse.en.md @@ -45,10 +45,15 @@ func main() { piscine.ListReverse(link) - for link.Head != nil { - fmt.Println(link.Head.Data) - link.Head = link.Head.Next + it := link.Head + + 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 2 1 +Tail &{1 } +Head &{4 0xc42000a140} student@ubuntu:~/piscine/test$ -``` +``` \ No newline at end of file From 8e780e049f5df44270a319fc5bc0d65ce0f1dd69 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 17:53:19 +0100 Subject: [PATCH 39/66] readme btreedeletenode from quest 12 --- subjects/btreedeletenode.en.md | 26 +++++++++++++------------- subjects/btreedeletenode.fr.md | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/subjects/btreedeletenode.en.md b/subjects/btreedeletenode.en.md index c367fe05..a2154fd7 100644 --- a/subjects/btreedeletenode.en.md +++ b/subjects/btreedeletenode.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function, BTreeDeleteNode, that deletes 'node' from the tree given by root. +Write a function, `BTreeDeleteNode`, that deletes a `node` from the tree given by root. The resulting tree should still follow the binary search tree rules. @@ -26,28 +26,28 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "4") + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "4") fmt.Println("Before delete:") - student.BTreeApplyInorder(root, fmt.Println) - root = student.BTreeDeleteNode(root, node) + piscine.BTreeApplyInorder(root, fmt.Println) + root = piscine.BTreeDeleteNode(root, node) fmt.Println("After delete:") - student.BTreeApplyInorder(root, fmt.Println) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreedeletenode$ go build -student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test Before delete: 1 4 @@ -57,5 +57,5 @@ After delete: 1 5 7 -student@ubuntu:~/student/btreedeletenode$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreedeletenode.fr.md b/subjects/btreedeletenode.fr.md index c367fe05..a2154fd7 100644 --- a/subjects/btreedeletenode.fr.md +++ b/subjects/btreedeletenode.fr.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 a `node` from the tree given by root. The resulting tree should still follow the binary search tree rules. @@ -26,28 +26,28 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "4") + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "4") fmt.Println("Before delete:") - student.BTreeApplyInorder(root, fmt.Println) - root = student.BTreeDeleteNode(root, node) + piscine.BTreeApplyInorder(root, fmt.Println) + root = piscine.BTreeDeleteNode(root, node) fmt.Println("After delete:") - student.BTreeApplyInorder(root, fmt.Println) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreedeletenode$ go build -student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test Before delete: 1 4 @@ -57,5 +57,5 @@ After delete: 1 5 7 -student@ubuntu:~/student/btreedeletenode$ +student@ubuntu:~/student/test$ ``` From 16aff61c314f5b79d418037ec67a492c79c27334 Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 18:19:25 +0100 Subject: [PATCH 40/66] add functions for the test of listforeach --- subjects/listforeach.en.md | 63 +++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/subjects/listforeach.en.md b/subjects/listforeach.en.md index 025c0e52..76359adb 100644 --- a/subjects/listforeach.en.md +++ b/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. -- 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 ```go -type node struct { - data interface{} - next *node +type NodeL struct { + Data interface{} + Next *NodeL +} + +type List struct { + Head *NodeL + Tail *NodeL } -type list struct { - head *node - tail *node +func ListForEach(l *List, f func(*NodeL)) { } -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() { - link := &list{} + link := &piscine.List{} - piscine.ListPushBack(link, 1) - piscine.ListPushBack(link, 2) - piscine.ListPushBack(link, 3) - piscine.ListPushBack(link, 4) + piscine.ListPushBack(link, "1") + piscine.ListPushBack(link, "2") + piscine.ListPushBack(link, "3") + piscine.ListPushBack(link, "5") - piscine.ListForEach(link, piscine.ListReverse) + piscine.ListForEach(link, piscine.Add2) - for link.head != nil { - fmt.Println(link.head.data) - link.head = link.head.next + it := link.Head + for it != nil { + fmt.Println(it.Data) + it = it.Next } } ``` @@ -57,9 +78,9 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -4 -3 -2 -1 +12 +22 +32 +52 student@ubuntu:~/piscine/test$ ``` From 662a06874b253bcea554a7e542cdf1af9982b10e Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 26 Jun 2019 09:47:54 +0100 Subject: [PATCH 41/66] reademe btreedeletenode from quest 12 --- subjects/btreedeletenode.en.md | 28 +++++++++++++--------------- subjects/btreedeletenode.fr.md | 28 +++++++++++++--------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/subjects/btreedeletenode.en.md b/subjects/btreedeletenode.en.md index c367fe05..d308f08b 100644 --- a/subjects/btreedeletenode.en.md +++ b/subjects/btreedeletenode.en.md @@ -2,12 +2,10 @@ ### 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. -This function must have the following signature. - ### Expected function ```go @@ -26,28 +24,28 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "4") + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "4") fmt.Println("Before delete:") - student.BTreeApplyInorder(root, fmt.Println) - root = student.BTreeDeleteNode(root, node) + piscine.BTreeApplyInorder(root, fmt.Println) + root = piscine.BTreeDeleteNode(root, node) fmt.Println("After delete:") - student.BTreeApplyInorder(root, fmt.Println) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreedeletenode$ go build -student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test Before delete: 1 4 @@ -57,5 +55,5 @@ After delete: 1 5 7 -student@ubuntu:~/student/btreedeletenode$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/btreedeletenode.fr.md b/subjects/btreedeletenode.fr.md index c367fe05..d308f08b 100644 --- a/subjects/btreedeletenode.fr.md +++ b/subjects/btreedeletenode.fr.md @@ -2,12 +2,10 @@ ### 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. -This function must have the following signature. - ### Expected function ```go @@ -26,28 +24,28 @@ package main import ( "fmt" - student ".." + piscine ".." ) func main() { - root := &student.TreeNode{Data: "4"} - student.BTreeInsertData(root, "1") - student.BTreeInsertData(root, "7") - student.BTreeInsertData(root, "5") - node := student.BTreeSearchItem(root, "4") + root := &piscine.TreeNode{Data: "4"} + piscine.BTreeInsertData(root, "1") + piscine.BTreeInsertData(root, "7") + piscine.BTreeInsertData(root, "5") + node := piscine.BTreeSearchItem(root, "4") fmt.Println("Before delete:") - student.BTreeApplyInorder(root, fmt.Println) - root = student.BTreeDeleteNode(root, node) + piscine.BTreeApplyInorder(root, fmt.Println) + root = piscine.BTreeDeleteNode(root, node) fmt.Println("After delete:") - student.BTreeApplyInorder(root, fmt.Println) + piscine.BTreeApplyInorder(root, fmt.Println) } ``` And its output : ```console -student@ubuntu:~/student/btreedeletenode$ go build -student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode +student@ubuntu:~/student/test$ go build +student@ubuntu:~/student/test$ ./test Before delete: 1 4 @@ -57,5 +55,5 @@ After delete: 1 5 7 -student@ubuntu:~/student/btreedeletenode$ +student@ubuntu:~/student/test$ ``` From 98cf1e002e0e27b290a775265fa3bafd0ad8e5b2 Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 26 Jun 2019 12:55:47 +0100 Subject: [PATCH 42/66] fix readme listsort from quest 11 --- subjects/listsort.en.md | 52 +++++++++++++------------------ subjects/listsort.fr.md | 69 ++++++++++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/subjects/listsort.en.md b/subjects/listsort.en.md index b690cb98..7672ad54 100644 --- a/subjects/listsort.en.md +++ b/subjects/listsort.en.md @@ -13,12 +13,12 @@ Write a function `ListSort` that sorts the linked list by ascending order. ### Expected function and structure ```go -type node struct { - data int - next *node +type Nodee struct { + Data int + Next *Nodee } -func ListSort(l *node) *node { +func ListSort(l *Nodee) *Nodee { } ``` @@ -32,53 +32,45 @@ package main import ( "fmt" + piscine ".." ) -//Prints the list -func PrintList(l *node) { +func PrintList(l *piscine.Nodee) { m := l for m != nil { - fmt.Print(m.data, " -> ") - m = m.next + fmt.Print(m.Data, " -> ") + m = m.Next } - fmt.Print(nil) fmt.Println() } -//insert elements -func listPushBack(l *node, data int) { - - n := &node{} - n.data = data - n.next = nil +func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { + n := &piscine.Nodee{Data: data} if l == nil { - l = n - return + return n } - iterator := l - for iterator.next != nil { - iterator = iterator.next + for iterator.Next != nil { + iterator = iterator.Next } - iterator.next = n + iterator.Next = n + return l } func main() { - link := &node{} + var link *piscine.Nodee - listPushBack(link, 5) - listPushBack(link, 4) - listPushBack(link, 3) - listPushBack(link, 2) - listPushBack(link, 1) + link = listPushBack(link, 5) + link = listPushBack(link, 4) + link = listPushBack(link, 3) + link = listPushBack(link, 2) + link = listPushBack(link, 1) PrintList(piscine.ListSort(link)) - } - ``` And its output : @@ -86,6 +78,6 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -> 1 -> 2 -> 3 -> 4 -> 5 -> +1 -> 2 -> 3 -> 4 -> 5 -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/listsort.fr.md b/subjects/listsort.fr.md index 7db913a6..7672ad54 100644 --- a/subjects/listsort.fr.md +++ b/subjects/listsort.fr.md @@ -1,44 +1,83 @@ -## 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`. +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 -func CountIf(f func(string) bool, tab []string) int { +type Nodee struct { + Data int + Next *Nodee +} + +func ListSort(l *Nodee) *Nodee { + } ``` -### Utilisation +### Usage -Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : +Here is a possible [program](TODO-LINK) to test your function : ```go package main import ( "fmt" + piscine ".." ) +func PrintList(l *piscine.Nodee) { + m := l + for m != nil { + fmt.Print(m.Data, " -> ") + m = m.Next + } + fmt.Print(nil) + fmt.Println() +} + +func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { + n := &piscine.Nodee{Data: data} + + if l == nil { + return n + } + iterator := l + for iterator.Next != nil { + iterator = iterator.Next + } + iterator.Next = n + return l +} + 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) + var link *piscine.Nodee + + link = listPushBack(link, 5) + link = listPushBack(link, 4) + link = listPushBack(link, 3) + link = listPushBack(link, 2) + link = listPushBack(link, 1) + + PrintList(piscine.ListSort(link)) } ``` -Et son résultat : +And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +1 -> 2 -> 3 -> 4 -> 5 -> student@ubuntu:~/piscine/test$ ``` From f103a9c3301e7dcdceed700665fa731f1ddad28f Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 26 Jun 2019 13:08:49 +0100 Subject: [PATCH 43/66] readme sortlistinsert from quest 11 --- subjects/sortlistinsert.en.md | 51 ++++++++++++--------------- subjects/sortlistinsert.fr.md | 66 +++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 44 deletions(-) diff --git a/subjects/sortlistinsert.en.md b/subjects/sortlistinsert.en.md index b84a35b9..8b6ab31b 100644 --- a/subjects/sortlistinsert.en.md +++ b/subjects/sortlistinsert.en.md @@ -11,12 +11,7 @@ Write a function `SortListInsert` that inserts `data_ref` in the linked list, bu ### Expected function and structure ```go -type node struct { - data int - next *node -} - -func SortListInsert(l *node, data_ref int) *node{ +func SortListInsert(l *Nodee, data_ref int) *Nodee{ } ``` @@ -30,50 +25,48 @@ package main import ( "fmt" + piscine ".." ) -//Prints the list -func PrintList(l *node) { +func PrintList(l *piscine.Nodee) { m := l for m != nil { - fmt.Print(m.data, " -> ") - m = m.next + fmt.Print(m.Data, " -> ") + m = m.Next } fmt.Print(nil) fmt.Println() } -//insert elements -func listPushBack(l *node, data int) { - n := &node{} - n.data = data - n.next = nil + +func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { + n := &piscine.Nodee{Data: data} + if l == nil { - l = n - return + return n } iterator := l - for iterator.next != nil { - iterator = iterator.next + for iterator.Next != nil { + iterator = iterator.Next } - iterator.next = n + iterator.Next = n + return l } func main() { - link := &node{} + var link *piscine.Nodee - listPushBack(link, 1) - listPushBack(link, 4) - listPushBack(link, 9) + link = listPushBack(link, 1) + link = listPushBack(link, 4) + link = listPushBack(link, 9) PrintList(link) - link = sortListInsert(link, -2) - link = sortListInsert(link, 2) + link = piscine.SortListInsert(link, -2) + link = piscine.SortListInsert(link, 2) PrintList(link) } - ``` And its output : @@ -81,7 +74,7 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test --2 -> 0 -> 1 -> 2 -> 4 -> 9 -> -lee@lee:~/Documents/work/day11/11-16-sortlistinsert/so +1 -> 4 -> 9 -> +-2 -> 1 -> 2 -> 4 -> 9 -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/sortlistinsert.fr.md b/subjects/sortlistinsert.fr.md index 7db913a6..8b6ab31b 100644 --- a/subjects/sortlistinsert.fr.md +++ b/subjects/sortlistinsert.fr.md @@ -1,44 +1,80 @@ -## 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`. +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 -func CountIf(f func(string) bool, tab []string) int { +func SortListInsert(l *Nodee, data_ref int) *Nodee{ + } ``` -### Utilisation +### Usage -Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : +Here is a possible [program](TODO-LINK) to test your function : ```go package main import ( "fmt" + piscine ".." ) +func PrintList(l *piscine.Nodee) { + m := l + for m != nil { + fmt.Print(m.Data, " -> ") + m = m.Next + } + fmt.Print(nil) + fmt.Println() +} + +func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { + n := &piscine.Nodee{Data: data} + + if l == nil { + return n + } + iterator := l + for iterator.Next != nil { + iterator = iterator.Next + } + iterator.Next = n + return l +} + 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) + + var link *piscine.Nodee + + link = listPushBack(link, 1) + link = listPushBack(link, 4) + 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 student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +1 -> 4 -> 9 -> +-2 -> 1 -> 2 -> 4 -> 9 -> student@ubuntu:~/piscine/test$ ``` From 3cc1ca3f382a7505da42a4b9addd640756db84f1 Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 26 Jun 2019 13:31:57 +0100 Subject: [PATCH 44/66] readme sortedlistmerge from quest 11 --- subjects/sortedlistmerge.en.md | 57 ++++++++++++++++------------ subjects/sortedlistmerge.fr.md | 68 ++++++++++++++++++++++++++-------- 2 files changed, 87 insertions(+), 38 deletions(-) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index 7653c3e0..8db19ee1 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -2,7 +2,7 @@ ### 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 mereges two lists, `n1` and `n2`, but it as to join them in ascending order. - Tip each list as to be already sorted. @@ -11,12 +11,7 @@ Write a function `SortedListMerge` that mereges two lists, `l1` and `l2`, but it ### Expected function and structure ```go -type node struct { - data interface{} - next *node -} - -func SortedListMerge(l1 *node, l2 *node) *node { +func SortedListMerge(n1 *Nodee, n2 *Nodee) *Nodee { } ``` @@ -30,35 +25,51 @@ package main import ( "fmt" + piscine ".." ) -func PrintList(l *list) { - m := l.head +type node = piscine.Nodee +type nodes = piscine.Nodee + +func PrintList(l *piscine.Nodee) { + m := l for m != nil { - fmt.Print(m.data, " -> ") - m = m.next + fmt.Print(m.Data, " -> ") + m = m.Next } - fmt.Print(nil) fmt.Println() } +func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { + n := &piscine.Nodee{Data: data} + + if l == nil { + return n + } + iterator := l + for iterator.Next != nil { + iterator = iterator.Next + } + iterator.Next = n + return l +} + func main() { - link := &list{} - link2 := &list{} + var link *node + var link2 *nodes - piscine.ListPushBack(link, "5") - piscine.ListPushBack(link, "3") - piscine.ListPushBack(link, "7") + link = listPushBack(link, 5) + link = listPushBack(link, 3) + link = listPushBack(link, 7) - piscine.ListPushBack(link2, "1") - piscine.ListPushBack(link2, "-2") - piscine.ListPushBack(link2, "4") - piscine.ListPushBack(link2, "6") + link2 = listPushBack(link2, -2) + link2 = listPushBack(link2, 4) - PrintList(SortedListMerge(link, link2)) + PrintList(piscine.SortedListMerge(link2, link)) } + ``` And its output : @@ -66,6 +77,6 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test --2 -> 0 -> 0 -> 1 -> 3 -> 4 -> 5 -> 6 -> 7 -> +-2 -> 3 -> 4 -> 5 -> 7 -> student@ubuntu:~/piscine/test$ ``` diff --git a/subjects/sortedlistmerge.fr.md b/subjects/sortedlistmerge.fr.md index 7db913a6..8db19ee1 100644 --- a/subjects/sortedlistmerge.fr.md +++ b/subjects/sortedlistmerge.fr.md @@ -1,44 +1,82 @@ -## 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`. +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 -func CountIf(f func(string) bool, tab []string) int { +func SortedListMerge(n1 *Nodee, n2 *Nodee) *Nodee { + } ``` -### Utilisation +### Usage -Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : +Here is a possible [program](TODO-LINK) to test your function : ```go package main import ( "fmt" + piscine ".." ) +type node = piscine.Nodee +type nodes = piscine.Nodee + +func PrintList(l *piscine.Nodee) { + m := l + for m != nil { + fmt.Print(m.Data, " -> ") + m = m.Next + } + fmt.Print(nil) + fmt.Println() +} + +func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { + n := &piscine.Nodee{Data: data} + + if l == nil { + return n + } + iterator := l + for iterator.Next != nil { + iterator = iterator.Next + } + iterator.Next = n + return l +} + 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) + var link *node + var link2 *nodes + + link = listPushBack(link, 5) + link = listPushBack(link, 3) + 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 student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -0 -2 +-2 -> 3 -> 4 -> 5 -> 7 -> student@ubuntu:~/piscine/test$ ``` From 069c375205efa4b8ca6b62df7b091ba5a2b6a41c Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 26 Jun 2019 14:21:20 +0100 Subject: [PATCH 45/66] fix Nodee to NodeI --- subjects/listsort.en.md | 16 ++++++++-------- subjects/listsort.fr.md | 14 +++++++------- subjects/sortedlistmerge.en.md | 14 +++++++------- subjects/sortedlistmerge.fr.md | 14 +++++++------- subjects/sortlistinsert.en.md | 12 ++++++------ subjects/sortlistinsert.fr.md | 12 ++++++------ 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/subjects/listsort.en.md b/subjects/listsort.en.md index 7672ad54..44ec9e2a 100644 --- a/subjects/listsort.en.md +++ b/subjects/listsort.en.md @@ -1,4 +1,4 @@ -## listpushback +## listsort ### Instructions @@ -13,12 +13,12 @@ Write a function `ListSort` that sorts the linked list by ascending order. ### Expected function and structure ```go -type Nodee struct { +type NodeI struct { Data int - Next *Nodee + Next *NodeI } -func ListSort(l *Nodee) *Nodee { +func ListSort(l *NodeI) *NodeI { } ``` @@ -36,7 +36,7 @@ import ( piscine ".." ) -func PrintList(l *piscine.Nodee) { +func PrintList(l *piscine.NodeI) { m := l for m != nil { fmt.Print(m.Data, " -> ") @@ -46,8 +46,8 @@ func PrintList(l *piscine.Nodee) { fmt.Println() } -func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { - n := &piscine.Nodee{Data: data} +func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { + n := &piscine.NodeI{Data: data} if l == nil { return n @@ -61,7 +61,7 @@ func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { } func main() { - var link *piscine.Nodee + var link *piscine.NodeI link = listPushBack(link, 5) link = listPushBack(link, 4) diff --git a/subjects/listsort.fr.md b/subjects/listsort.fr.md index 7672ad54..c146d367 100644 --- a/subjects/listsort.fr.md +++ b/subjects/listsort.fr.md @@ -13,12 +13,12 @@ Write a function `ListSort` that sorts the linked list by ascending order. ### Expected function and structure ```go -type Nodee struct { +type NodeI struct { Data int - Next *Nodee + Next *NodeI } -func ListSort(l *Nodee) *Nodee { +func ListSort(l *NodeI) *NodeI { } ``` @@ -36,7 +36,7 @@ import ( piscine ".." ) -func PrintList(l *piscine.Nodee) { +func PrintList(l *piscine.NodeI) { m := l for m != nil { fmt.Print(m.Data, " -> ") @@ -46,8 +46,8 @@ func PrintList(l *piscine.Nodee) { fmt.Println() } -func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { - n := &piscine.Nodee{Data: data} +func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { + n := &piscine.NodeI{Data: data} if l == nil { return n @@ -61,7 +61,7 @@ func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { } func main() { - var link *piscine.Nodee + var link *piscine.NodeI link = listPushBack(link, 5) link = listPushBack(link, 4) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index 8db19ee1..db9a3b10 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -1,4 +1,4 @@ -## listpushback +## sortedlistmerge ### Instructions @@ -11,7 +11,7 @@ Write a function `SortedListMerge` that mereges two lists, `n1` and `n2`, but it ### Expected function and structure ```go -func SortedListMerge(n1 *Nodee, n2 *Nodee) *Nodee { +func SortedListMerge(n1 *NodeI, n2 *NodeI) *NodeI { } ``` @@ -29,10 +29,10 @@ import ( piscine ".." ) -type node = piscine.Nodee -type nodes = piscine.Nodee +type node = piscine.NodeI +type nodes = piscine.NodeI -func PrintList(l *piscine.Nodee) { +func PrintList(l *piscine.NodeI) { m := l for m != nil { fmt.Print(m.Data, " -> ") @@ -42,8 +42,8 @@ func PrintList(l *piscine.Nodee) { fmt.Println() } -func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { - n := &piscine.Nodee{Data: data} +func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { + n := &piscine.NodeI{Data: data} if l == nil { return n diff --git a/subjects/sortedlistmerge.fr.md b/subjects/sortedlistmerge.fr.md index 8db19ee1..db9a3b10 100644 --- a/subjects/sortedlistmerge.fr.md +++ b/subjects/sortedlistmerge.fr.md @@ -1,4 +1,4 @@ -## listpushback +## sortedlistmerge ### Instructions @@ -11,7 +11,7 @@ Write a function `SortedListMerge` that mereges two lists, `n1` and `n2`, but it ### Expected function and structure ```go -func SortedListMerge(n1 *Nodee, n2 *Nodee) *Nodee { +func SortedListMerge(n1 *NodeI, n2 *NodeI) *NodeI { } ``` @@ -29,10 +29,10 @@ import ( piscine ".." ) -type node = piscine.Nodee -type nodes = piscine.Nodee +type node = piscine.NodeI +type nodes = piscine.NodeI -func PrintList(l *piscine.Nodee) { +func PrintList(l *piscine.NodeI) { m := l for m != nil { fmt.Print(m.Data, " -> ") @@ -42,8 +42,8 @@ func PrintList(l *piscine.Nodee) { fmt.Println() } -func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { - n := &piscine.Nodee{Data: data} +func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { + n := &piscine.NodeI{Data: data} if l == nil { return n diff --git a/subjects/sortlistinsert.en.md b/subjects/sortlistinsert.en.md index 8b6ab31b..285ea95d 100644 --- a/subjects/sortlistinsert.en.md +++ b/subjects/sortlistinsert.en.md @@ -1,4 +1,4 @@ -## listpushback +## sortlistinsert ### Instructions @@ -11,7 +11,7 @@ Write a function `SortListInsert` that inserts `data_ref` in the linked list, bu ### Expected function and structure ```go -func SortListInsert(l *Nodee, data_ref int) *Nodee{ +func SortListInsert(l *NodeI, data_ref int) *NodeI{ } ``` @@ -29,7 +29,7 @@ import ( piscine ".." ) -func PrintList(l *piscine.Nodee) { +func PrintList(l *piscine.NodeI) { m := l for m != nil { fmt.Print(m.Data, " -> ") @@ -39,8 +39,8 @@ func PrintList(l *piscine.Nodee) { fmt.Println() } -func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { - n := &piscine.Nodee{Data: data} +func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { + n := &piscine.NodeI{Data: data} if l == nil { return n @@ -55,7 +55,7 @@ func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { func main() { - var link *piscine.Nodee + var link *piscine.NodeI link = listPushBack(link, 1) link = listPushBack(link, 4) diff --git a/subjects/sortlistinsert.fr.md b/subjects/sortlistinsert.fr.md index 8b6ab31b..285ea95d 100644 --- a/subjects/sortlistinsert.fr.md +++ b/subjects/sortlistinsert.fr.md @@ -1,4 +1,4 @@ -## listpushback +## sortlistinsert ### Instructions @@ -11,7 +11,7 @@ Write a function `SortListInsert` that inserts `data_ref` in the linked list, bu ### Expected function and structure ```go -func SortListInsert(l *Nodee, data_ref int) *Nodee{ +func SortListInsert(l *NodeI, data_ref int) *NodeI{ } ``` @@ -29,7 +29,7 @@ import ( piscine ".." ) -func PrintList(l *piscine.Nodee) { +func PrintList(l *piscine.NodeI) { m := l for m != nil { fmt.Print(m.Data, " -> ") @@ -39,8 +39,8 @@ func PrintList(l *piscine.Nodee) { fmt.Println() } -func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { - n := &piscine.Nodee{Data: data} +func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { + n := &piscine.NodeI{Data: data} if l == nil { return n @@ -55,7 +55,7 @@ func listPushBack(l *piscine.Nodee, data int) *piscine.Nodee { func main() { - var link *piscine.Nodee + var link *piscine.NodeI link = listPushBack(link, 1) link = listPushBack(link, 4) From 6f36533a119bb62b4d3a1d702a058c25f75d978b Mon Sep 17 00:00:00 2001 From: Augusto Date: Wed, 26 Jun 2019 16:56:41 +0100 Subject: [PATCH 46/66] fix change listfind function --- subjects/listfind.en.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/subjects/listfind.en.md b/subjects/listfind.en.md index 4979b846..c84208e7 100644 --- a/subjects/listfind.en.md +++ b/subjects/listfind.en.md @@ -1,31 +1,29 @@ -## listpushback +## listfind ### 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`. -- Use pointers wen ever you can. - ### Expected function and structure ```go -type node struct { - data interface{} - next *node +type NodeL struct { + Data interface{} + Next *NodeL } -type list struct { - head *node - tail *node +type List struct { + Head *NodeL + 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,14 @@ import ( ) func main() { - link := &list{} + link := &piscine.List{} piscine.ListPushBack(link, "hello") piscine.ListPushBack(link, "hello1") piscine.ListPushBack(link, "hello2") piscine.ListPushBack(link, "hello3") - fmt.Println(piscine.ListFind(link, compStr)) + fmt.Println(piscine.ListFind(link, interface{}("hello2"), piscine.CompStr)) } ``` @@ -62,3 +60,6 @@ student@ubuntu:~/piscine/test$ ./test 0xc42000a0a0 student@ubuntu:~/piscine/test$ ``` +### Note + +- The address may be different in each execution of the program. \ No newline at end of file From 988689d8399f7abdfd083022e936f1ab65988ee8 Mon Sep 17 00:00:00 2001 From: Augusto Date: Wed, 26 Jun 2019 16:58:28 +0100 Subject: [PATCH 47/66] change function ListForEachIf and some instructions --- subjects/listforeachif.en.md | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/subjects/listforeachif.en.md b/subjects/listforeachif.en.md index 501d047f..ef3d975a 100644 --- a/subjects/listforeachif.en.md +++ b/subjects/listforeachif.en.md @@ -2,32 +2,34 @@ ### 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. + - `comp` 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 ```go -type node struct { - data interface{} - next *node +type NodeL struct { + Data interface{} + Next *NodeL } -type list struct { - head *node - tail *node +type List struct { + Head *NodeL + Tail *NodeL } -func CompStr(l *list) bool { +func CompStr(l *NodeL) bool { } -func ListForEachIf(l *list, f func(l *list), comp func(l *list) bool) { +func ListForEachIf(l *List, f func(*NodeL), comp func(*NodeL) bool) { } ``` @@ -44,26 +46,26 @@ import ( piscine ".." ) -func PrintElem(l *list) { - fmt.Println(l.head.data) +func PrintElem(l *List) { + fmt.Println(l.Head.Data) } -func StringToInt(l *list) { +func StringToInt(l *List) { count := 1 - l.head.data = count + l.Head.Data = count } -func PrintList(l *list) { - m := l.head +func PrintList(l *List) { + m := l.Head for m != nil { - fmt.Print(m.data, " -> ") - m = m.next + fmt.Print(m.Data, " -> ") + m = m.Next } - fmt.Print(l.tail) + fmt.Print(l.Tail) } func main() { - link := &list{} + link := &List{} piscine.ListPushBack(link, 1) piscine.ListPushBack(link, "hello") From 366cd76706c7156142702beaec278c4436f1a78d Mon Sep 17 00:00:00 2001 From: Augusto Date: Wed, 26 Jun 2019 18:38:37 +0100 Subject: [PATCH 48/66] fix listforeachif readme --- subjects/listforeachif.en.md | 69 ++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/subjects/listforeachif.en.md b/subjects/listforeachif.en.md index ef3d975a..ed62981a 100644 --- a/subjects/listforeachif.en.md +++ b/subjects/listforeachif.en.md @@ -1,4 +1,4 @@ -## listpushback +## listforeachif ### Instructions @@ -8,7 +8,7 @@ Write a function `ListForEachIf` that applies a function given as argument to th - `f` is a functions that is applied to the node. - - `comp` 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. + - `` 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`. @@ -25,11 +25,37 @@ type List struct { Tail *NodeL } -func CompStr(l *NodeL) bool { +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), comp func(*NodeL) bool) { +func ListForEachIf(l *List, f func(*NodeL), cond func(*NodeL) bool) { } ``` @@ -42,30 +68,29 @@ Here is a possible [program](TODO-LINK) to test your function : package main import ( - "fmt" piscine ".." + "fmt" ) -func PrintElem(l *List) { - fmt.Println(l.Head.Data) +func PrintElem(node *piscine.NodeL) { + fmt.Println(node.Data) } -func StringToInt(l *List) { - count := 1 - l.Head.Data = count +func StringToInt(node *piscine.NodeL) { + node.Data = 2 } -func PrintList(l *List) { - m := l.Head - for m != nil { - fmt.Print(m.Data, " -> ") - m = m.Next +func PrintList(l *piscine.List) { + it := l.Head + for it != nil { + fmt.Print(it.Data, "->") + it = it.Next } - - fmt.Print(l.Tail) + fmt.Println() } + func main() { - link := &List{} + link := &piscine.List{} piscine.ListPushBack(link, 1) piscine.ListPushBack(link, "hello") @@ -75,16 +100,16 @@ func main() { piscine.ListPushBack(link, "!") piscine.ListPushBack(link, 54) - PrintAllList(link) + PrintList(link) fmt.Println() 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--------") - PrintAllList(link) + PrintList(link) fmt.Println() } From 73d755f5049450619326fd2a164553d6ecc49aa2 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 09:31:25 +0100 Subject: [PATCH 49/66] missing Comp --- subjects/listforeachif.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listforeachif.en.md b/subjects/listforeachif.en.md index ed62981a..74c91cf9 100644 --- a/subjects/listforeachif.en.md +++ b/subjects/listforeachif.en.md @@ -8,7 +8,7 @@ Write a function `ListForEachIf` that applies a function given as argument to th - `f` is a functions that is applied to the node. - - `` 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. + - `Comp` 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`. From 0754ae1f30cc619ecb32d446550caf8cccb7711c Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 09:32:58 +0100 Subject: [PATCH 50/66] missing Comp to comd --- subjects/listforeachif.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listforeachif.en.md b/subjects/listforeachif.en.md index 74c91cf9..40cd1ccb 100644 --- a/subjects/listforeachif.en.md +++ b/subjects/listforeachif.en.md @@ -8,7 +8,7 @@ Write a function `ListForEachIf` that applies a function given as argument to th - `f` is a functions that is applied to the node. - - `Comp` 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 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`. From f17a32240c7b40eb939663977aa7e7da4062baae Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 09:55:29 +0100 Subject: [PATCH 51/66] fix readme messing title --- subjects/btreeapplyinorder.en.md | 2 +- subjects/btreeapplypostorder.en.md | 2 +- subjects/btreeapplypreorder.en.md | 2 +- subjects/btreeisbinary.en.md | 2 +- subjects/btreelevelcount.en.md | 2 +- subjects/btreesearchitem.en.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/subjects/btreeapplyinorder.en.md b/subjects/btreeapplyinorder.en.md index e182df07..bfd30ea0 100644 --- a/subjects/btreeapplyinorder.en.md +++ b/subjects/btreeapplyinorder.en.md @@ -1,4 +1,4 @@ -## btreeinsertdata +## btreeapplyinorder ### Instructions diff --git a/subjects/btreeapplypostorder.en.md b/subjects/btreeapplypostorder.en.md index e386d350..327b4458 100644 --- a/subjects/btreeapplypostorder.en.md +++ b/subjects/btreeapplypostorder.en.md @@ -1,4 +1,4 @@ -## btreeinsertdata +## btreeapplypostorder ### Instructions diff --git a/subjects/btreeapplypreorder.en.md b/subjects/btreeapplypreorder.en.md index 4a43b56a..96e68bc3 100644 --- a/subjects/btreeapplypreorder.en.md +++ b/subjects/btreeapplypreorder.en.md @@ -1,4 +1,4 @@ -## btreeinsertdata +## btreeapplypreorder ### Instructions diff --git a/subjects/btreeisbinary.en.md b/subjects/btreeisbinary.en.md index 2a93d314..578f7c3f 100644 --- a/subjects/btreeisbinary.en.md +++ b/subjects/btreeisbinary.en.md @@ -2,7 +2,7 @@ ### 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. diff --git a/subjects/btreelevelcount.en.md b/subjects/btreelevelcount.en.md index ef9c7806..14a097e5 100644 --- a/subjects/btreelevelcount.en.md +++ b/subjects/btreelevelcount.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function, BTreeLevelCount, that return the number of levels of the tree (height of the tree) +Write a function, `BTreeLevelCount`, that return the number of levels of the tree (height of the tree) ### Expected function diff --git a/subjects/btreesearchitem.en.md b/subjects/btreesearchitem.en.md index 2367eead..6cfa461d 100644 --- a/subjects/btreesearchitem.en.md +++ b/subjects/btreesearchitem.en.md @@ -1,4 +1,4 @@ -## btreeinsertdata +## btreesearchitem ### Instructions From 92f7be598f61d9f3f6426a189f33f8970e998aca Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 10:13:31 +0100 Subject: [PATCH 52/66] readme listmerge sintaxe problems and fixing the function --- subjects/listmerge.en.md | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/subjects/listmerge.en.md b/subjects/listmerge.en.md index e29427f5..db7b4c8b 100644 --- a/subjects/listmerge.en.md +++ b/subjects/listmerge.en.md @@ -1,4 +1,4 @@ -## listpushback +## listmerge ### 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! -- Use pointers when ever you can. - ### Expected function and structure ```go -type node struct { - data interface{} - next *node +type NodeL struct { + Data interface{} + Next *NodeL } -type list struct { - head *node - tail *node +type List struct { + Head *NodeL + Tail *NodeL } -func ListMerge(l1 *list, l2 *list) { +func ListMerge(l1 *List, l2 *List) { } ``` @@ -35,34 +33,38 @@ package main import ( "fmt" + piscine ".." ) -func PrintList(l *list) { - m := l.head - for m != nil { - fmt.Print(m.data, " -> ") - m = m.next +func PrintList(l *piscine.List) { + it := l.Head + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next } - - fmt.Print(l.tail) - fmt.Println() + fmt.Print(nil, "\n") } func main() { - link := &list{} - link2 := &list{} + 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) } From e80dddbcf373cf93ef09d197e7cbbfb78322cfe7 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 10:34:48 +0100 Subject: [PATCH 53/66] fixing the main and some sintax errors --- subjects/listremoveif.en.md | 45 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/subjects/listremoveif.en.md b/subjects/listremoveif.en.md index b27311ed..e0c2ca77 100644 --- a/subjects/listremoveif.en.md +++ b/subjects/listremoveif.en.md @@ -4,24 +4,22 @@ 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. +- In case the list is empty print the message present a new line `\n`. ### Expected function and structure ```go -type node struct { +type NodeL struct { data interface{} - next *node + next *NodeL } -type list struct { - head *node - tail *node +type List struct { + Head *NodeL + Tail *NodeL } -func ListRemoveIf(l *list, data_ref interface{}) { +func ListRemoveIf(l *List, data_ref interface{}) { } ``` @@ -35,33 +33,28 @@ package main import ( "fmt" + piscine ".." ) -func PrintList(l *list) { - m := l.head - for m != nil { - fmt.Print(m.data, " -> ") - m = m.next +func PrintList(l *piscine.List) { + it := l.Head + for it != nil { + fmt.Print(it.Data, " -> ") + it = it.Next } - fmt.Print(l.tail) - fmt.Println() + fmt.Print(nil, "\n") } func main() { - link := &list{} - link2 := &list{} - link3 := &list{} - - fmt.Println("------answer-----") - ListRemoveIf(link3, 1) - fmt.Println() + link := &piscine.List{} + link2 := &piscine.List{} fmt.Println("----normal state----") piscine.ListPushBack(link2, 1) PrintList(link2) - ListRemoveIf(link2, 1) + piscine.ListRemoveIf(link2, 1) fmt.Println("------answer-----") PrintList(link) fmt.Println() @@ -80,7 +73,7 @@ func main() { piscine.ListPushBack(link, 1) PrintList(link) - ListRemoveIf(link, 1) + piscine.ListRemoveIf(link, 1) fmt.Println("------answer-----") PrintList(link) } @@ -93,7 +86,7 @@ And its output : student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test ------answer----- -no data on list + ----normal state---- 1 -> From 876a35b84221371731b0db8ce299655a7c3aa831 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Thu, 27 Jun 2019 10:38:48 +0100 Subject: [PATCH 54/66] Update listremoveif.en.md --- subjects/listremoveif.en.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/subjects/listremoveif.en.md b/subjects/listremoveif.en.md index e0c2ca77..c02d5738 100644 --- a/subjects/listremoveif.en.md +++ b/subjects/listremoveif.en.md @@ -4,8 +4,6 @@ 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 present a new line `\n`. - ### Expected function and structure ```go @@ -87,7 +85,6 @@ student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test ------answer----- - ----normal state---- 1 -> ------answer----- From a42e9540390eb8fa4b568706cf25cc595e7aeeb6 Mon Sep 17 00:00:00 2001 From: LEEDASILVA <39002521+LEEDASILVA@users.noreply.github.com> Date: Thu, 27 Jun 2019 10:39:49 +0100 Subject: [PATCH 55/66] Update listremoveif.en.md --- subjects/listremoveif.en.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/subjects/listremoveif.en.md b/subjects/listremoveif.en.md index c02d5738..24f692cb 100644 --- a/subjects/listremoveif.en.md +++ b/subjects/listremoveif.en.md @@ -83,8 +83,6 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test -------answer----- - ----normal state---- 1 -> ------answer----- From b2be697f9b3b30a0d7cef5209e5fc916b0664a5d Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 27 Jun 2019 10:49:27 +0100 Subject: [PATCH 56/66] add instruction to clarify the behavior of the function --- subjects/listfind.en.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subjects/listfind.en.md b/subjects/listfind.en.md index c84208e7..24f59ce8 100644 --- a/subjects/listfind.en.md +++ b/subjects/listfind.en.md @@ -48,7 +48,10 @@ func main() { piscine.ListPushBack(link, "hello2") piscine.ListPushBack(link, "hello3") - fmt.Println(piscine.ListFind(link, interface{}("hello2"), piscine.CompStr)) + found := piscine.ListFind(link, interface{}("hello2"), piscine.CompStr) + + fmt.Println(found) + fmt.Println(*found) } ``` @@ -58,6 +61,7 @@ And its output : student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test 0xc42000a0a0 +hello2 student@ubuntu:~/piscine/test$ ``` ### Note From 0ced0c4665d4956ed2e71114bc575a6ef7bbaa87 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 10:59:04 +0100 Subject: [PATCH 57/66] removing inconsistencies --- subjects/sortedlistmerge.en.md | 13 +++++-------- subjects/sortlistinsert.en.md | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index db9a3b10..c56501f4 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -6,8 +6,6 @@ Write a function `SortedListMerge` that mereges two lists, `n1` and `n2`, but it - Tip each list as to be already sorted. -- Use pointers when ever you can. - ### Expected function and structure ```go @@ -33,13 +31,12 @@ 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 { diff --git a/subjects/sortlistinsert.en.md b/subjects/sortlistinsert.en.md index 285ea95d..53517dfe 100644 --- a/subjects/sortlistinsert.en.md +++ b/subjects/sortlistinsert.en.md @@ -6,8 +6,6 @@ Write a function `SortListInsert` that inserts `data_ref` in the linked list, bu - The list as to be alredy sorted. -- Use pointers when ever you can. - ### Expected function and structure ```go @@ -30,13 +28,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 { From 14101bd2d06fc9a90a69498f3d7cbd01407f384a Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 27 Jun 2019 11:58:05 +0100 Subject: [PATCH 58/66] fix some sintax errors --- subjects/listremoveif.en.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subjects/listremoveif.en.md b/subjects/listremoveif.en.md index 24f692cb..8f744a1f 100644 --- a/subjects/listremoveif.en.md +++ b/subjects/listremoveif.en.md @@ -1,4 +1,4 @@ -## listpushback +## listremoveif ### Instructions @@ -8,8 +8,8 @@ Write a function `ListRemoveIf` that removes all elements that are equal to the ```go type NodeL struct { - data interface{} - next *NodeL + Data interface{} + Next *NodeL } type List struct { From 4f0820ebe2a3d76e8d28859b089629216356791a Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 13:42:24 +0100 Subject: [PATCH 59/66] fix main on test for the student --- subjects/listremoveif.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/listremoveif.en.md b/subjects/listremoveif.en.md index 24f692cb..d9b7a766 100644 --- a/subjects/listremoveif.en.md +++ b/subjects/listremoveif.en.md @@ -54,7 +54,7 @@ func main() { PrintList(link2) piscine.ListRemoveIf(link2, 1) fmt.Println("------answer-----") - PrintList(link) + PrintList(link2) fmt.Println() fmt.Println("----normal state----") From 1a64afac4c10bc5c38bc40088b8246e6b81c4b8a Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 14:42:34 +0100 Subject: [PATCH 60/66] remove inconsistencies on the main --- subjects/btreeapplypostorder.en.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/subjects/btreeapplypostorder.en.md b/subjects/btreeapplypostorder.en.md index 327b4458..de6825bc 100644 --- a/subjects/btreeapplypostorder.en.md +++ b/subjects/btreeapplypostorder.en.md @@ -7,7 +7,7 @@ Write a function that applies a function using a postorder walk to each element ### Expected function ```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 ( "fmt" - piscine "." + piscine ".." ) func main() { @@ -29,7 +29,7 @@ func main() { piscine.BTreeInsertData(root, "1") piscine.BTreeInsertData(root, "7") piscine.BTreeInsertData(root, "5") - BTreeApplyPostorder(root, fmt.Println) + piscine.BTreeApplyPostorder(root, fmt.Println) } ``` @@ -37,11 +37,11 @@ func main() { And its output : ```console -student@ubuntu:~/piscine/btreeinsertdata$ go build -student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata +student@ubuntu:~/piscine/test$ go build +student@ubuntu:~/piscine/test$ ./test 1 5 7 4 -student@ubuntu:~/piscine/btreeinsertdata$ +student@ubuntu:~/piscine/test$ ``` From 639ed15b968802780a9b09b066402a2108525d98 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 15:13:31 +0100 Subject: [PATCH 61/66] fix PrintList --- subjects/listsort.en.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/subjects/listsort.en.md b/subjects/listsort.en.md index 44ec9e2a..a9e5b8bf 100644 --- a/subjects/listsort.en.md +++ b/subjects/listsort.en.md @@ -6,10 +6,6 @@ Write a function `ListSort` that sorts the linked list by ascending order. - This time you only will have the `node` structure. -- Try to use recursive. - -- Use pointers when ever you can. - ### Expected function and structure ```go @@ -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 { From 1d3cee2d8766886979432724a515d86f34a1a821 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Jun 2019 16:29:14 +0100 Subject: [PATCH 62/66] deletion of inconsistent data --- subjects/sortedlistmerge.en.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index c56501f4..bb73dd32 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -27,9 +27,6 @@ import ( piscine ".." ) -type node = piscine.NodeI -type nodes = piscine.NodeI - func PrintList(l *piscine.NodeI) { it := l for it != nil { @@ -54,8 +51,8 @@ func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { } func main() { - var link *node - var link2 *nodes + var link *NodeI + var link2 *NodeI link = listPushBack(link, 5) link = listPushBack(link, 3) From bba71edbef5511cd9a783074431ee85076da48a5 Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 27 Jun 2019 17:47:32 +0100 Subject: [PATCH 63/66] fix readme for listsortinsert exercise --- subjects/{sortList.fr.md => sortlist.en.md} | 2 +- subjects/{sortList.en.md => sortlist.fr.md} | 0 subjects/sortlistinsert.en.md | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename subjects/{sortList.fr.md => sortlist.en.md} (98%) rename subjects/{sortList.en.md => sortlist.fr.md} (100%) diff --git a/subjects/sortList.fr.md b/subjects/sortlist.en.md similarity index 98% rename from subjects/sortList.fr.md rename to subjects/sortlist.en.md index 57ce66e1..fc054af1 100644 --- a/subjects/sortList.fr.md +++ b/subjects/sortlist.en.md @@ -1,4 +1,4 @@ -## sortList +## sortlist ### Instructions diff --git a/subjects/sortList.en.md b/subjects/sortlist.fr.md similarity index 100% rename from subjects/sortList.en.md rename to subjects/sortlist.fr.md diff --git a/subjects/sortlistinsert.en.md b/subjects/sortlistinsert.en.md index 53517dfe..aff98a7b 100644 --- a/subjects/sortlistinsert.en.md +++ b/subjects/sortlistinsert.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `SortListInsert` that inserts `data_ref` in the linked list, but 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. ### Expected function and structure From e94fdc6662d9cd672a06dffcfbd77786fe0a636f Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 27 Jun 2019 17:53:37 +0100 Subject: [PATCH 64/66] clarify instructions for the sortedlistmerge exercise --- subjects/sortedlistmerge.en.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index bb73dd32..0e44d3dc 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a function `SortedListMerge` that mereges two lists, `n1` and `n2`, but it as to join them in ascending order. +Write a function `SortedListMerge` that merges two lists, `n1` and `n2`, but it as to join them in ascending order. -- Tip each list as to be already sorted. +- Assume that `n1` and `n2` are already sorted ### Expected function and structure From dc5545474ce7ae73d0fe7f46cb88095e3340af5d Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 27 Jun 2019 18:43:47 +0100 Subject: [PATCH 65/66] fix typo in sortedlistmerged --- subjects/sortedlistmerge.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index 0e44d3dc..1aba0ed4 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function `SortedListMerge` that merges two lists, `n1` and `n2`, 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. - Assume that `n1` and `n2` are already sorted From bc992482b000e949d1b4e5871744f77f341ae4b8 Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 27 Jun 2019 19:36:44 +0100 Subject: [PATCH 66/66] fix main and usage of sortedlistmerge exercise --- subjects/sortedlistmerge.en.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/subjects/sortedlistmerge.en.md b/subjects/sortedlistmerge.en.md index 1aba0ed4..227b06a0 100644 --- a/subjects/sortedlistmerge.en.md +++ b/subjects/sortedlistmerge.en.md @@ -51,19 +51,18 @@ func listPushBack(l *piscine.NodeI, data int) *piscine.NodeI { } func main() { - var link *NodeI - var link2 *NodeI + 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 : @@ -71,6 +70,6 @@ And its output : ```console student@ubuntu:~/piscine/test$ go build student@ubuntu:~/piscine/test$ ./test --2 -> 3 -> 4 -> 5 -> 7 -> +-2 -> 3 -> 5 -> 7 -> 9 -> student@ubuntu:~/piscine/test$ ```