From c2ebaccdda3af994c67a7bb8e84063737655676e Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 11:13:17 +0100 Subject: [PATCH 01/11] 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 a36cac71759b2d145b7d61fb1a3be1fabdcc7f43 Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 21 Jun 2019 16:02:03 +0100 Subject: [PATCH 02/11] 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 ebbda76a9b1c1bd25eef79117f4765f73d5095c3 Mon Sep 17 00:00:00 2001 From: lee Date: Mon, 24 Jun 2019 17:46:39 +0100 Subject: [PATCH 03/11] 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 525d91717ac8a74964c1bc1bd554b32b8a8c4547 Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 11:27:08 +0100 Subject: [PATCH 04/11] 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 c4ab04db9c5649c3af4b4ae6afd8b9b4906fe9cc Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 25 Jun 2019 12:44:10 +0100 Subject: [PATCH 05/11] 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 06/11] 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 07/11] 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 08/11] 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 09/11] 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 0c3454c9f9eb0f3033fff0cc477a0211b2c4007b Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 16:59:06 +0100 Subject: [PATCH 10/11] 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 16aff61c314f5b79d418037ec67a492c79c27334 Mon Sep 17 00:00:00 2001 From: Augusto Date: Tue, 25 Jun 2019 18:19:25 +0100 Subject: [PATCH 11/11] 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$ ```