diff --git a/subjects/btreeapplybylevel.en.md b/subjects/btreeapplybylevel.en.md index 85cd3eb04..e964f86af 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 85cd3eb04..e964f86af 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$ ``` diff --git a/subjects/btreeisbinary.en.md b/subjects/btreeisbinary.en.md index e57a11a95..2a93d3143 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 e57a11a95..2a93d3143 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$ ``` diff --git a/subjects/btreelevelcount.en.md b/subjects/btreelevelcount.en.md index 2576e1099..ef9c7806f 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 2576e1099..ef9c7806f 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$ ``` diff --git a/subjects/btreemax.en.md b/subjects/btreemax.en.md index dc389960b..3fa2bc5c3 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 dc389960b..3fa2bc5c3 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$ ``` diff --git a/subjects/btreemin.en.md b/subjects/btreemin.en.md index f34718569..8de2f9a04 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 f34718569..8de2f9a04 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$ ``` diff --git a/subjects/btreetransplant.en.md b/subjects/btreetransplant.en.md index e80939149..0e8438a7f 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 e80939149..0e8438a7f 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$ ``` diff --git a/subjects/listforeach.en.md b/subjects/listforeach.en.md index 025c0e529..76359adbb 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$ ```