forked from root/public
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
766 B
48 lines
766 B
![]()
5 years ago
|
## btreeprintroot
|
||
5 years ago
|
|
||
5 years ago
|
### Instructions
|
||
5 years ago
|
|
||
|
Write a function to print the value of the root node of a binary tree.
|
||
|
The nodes must be defined as follows:
|
||
|
|
||
5 years ago
|
### Expected function
|
||
5 years ago
|
|
||
|
```go
|
||
|
type TreeNode struct {
|
||
|
left, right *TreeNode
|
||
|
data string
|
||
|
}
|
||
|
|
||
|
func PrintRoot(root *TreeNode){
|
||
|
|
||
|
}
|
||
|
```
|
||
|
|
||
5 years ago
|
### Usage
|
||
5 years ago
|
|
||
5 years ago
|
Here is a possible program to test your function :
|
||
5 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
func main() {
|
||
![]()
4 years ago
|
// rootNode initialized with the value "who"
|
||
|
// rootNode1 initialized with the value "are"
|
||
|
// rootNode2 initialized with the value "you"
|
||
5 years ago
|
printRoot(rootNode)
|
||
|
printRoot(rootNode1)
|
||
|
printRoot(rootNode2)
|
||
5 years ago
|
}
|
||
|
```
|
||
|
|
||
|
And its output :
|
||
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/printroot$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/printroot$ ./printroot
|
||
5 years ago
|
who
|
||
|
are
|
||
|
you
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$
|
||
5 years ago
|
```
|