|
|
|
## btreeprintroot
|
|
|
|
|
|
|
|
### Instructions
|
|
|
|
|
|
|
|
Write a function to print the value of the root node of a binary tree.
|
|
|
|
The nodes must be defined as follows:
|
|
|
|
|
|
|
|
### Expected function
|
|
|
|
|
|
|
|
```go
|
|
|
|
type TreeNode struct {
|
|
|
|
left, right *TreeNode
|
|
|
|
data string
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrintRoot(root *TreeNode){
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
Here is a possible program to test your function :
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
func main() {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// rootNode initialized with the value "who"
|
|
|
|
// rootNode1 initialized with the value "are"
|
|
|
|
// rootNode2 initialized with the value "you"
|
|
|
|
printRoot(rootNode)
|
|
|
|
printRoot(rootNode1)
|
|
|
|
printRoot(rootNode2)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
And its output :
|
|
|
|
|
|
|
|
```console
|
|
|
|
student@ubuntu:~/[[ROOT]]/printroot$ go build
|
|
|
|
student@ubuntu:~/[[ROOT]]/printroot$ ./printroot
|
|
|
|
who
|
|
|
|
are
|
|
|
|
you
|
|
|
|
student@ubuntu:~/[[ROOT]]/test$
|
|
|
|
```
|