1 Star 0 Fork 0

叶明志 / golang练习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 772 Bytes
一键复制 编辑 原始数据 按行查看 历史
叶明志 提交于 2019-06-27 23:25 . 二叉树的使用(略)
package main
import (
"fmt"
"math/rand"
)
type Student struct {
Name string
Age int
Score float32
}
type Bitree struct {
Name string
Age int
left *Bitree
right *Bitree
}
func testStruct() {
// var stu *Student=new(Student)
// var stu *Student=&Student{
// Name:"yang",
// }
var stu Student = Student{
Name: "yang",
}
fmt.Println(stu.Name)
}
func testBitree() {
var node1 *Bitree = &Bitree{
Name: "yang",
Age: rand.Intn(100),
}
var node2 *Bitree = new(Bitree)
node2.Name = "hu"
node2.Age = rand.Intn(100)
node1.left = node2
nodePrint(node1)
}
func nodePrint(p *Bitree) {
if p == nil {
return
} else {
fmt.Println(p.Name, p.Age)
nodePrint(p.left)
nodePrint(p.right)
}
}
func main() {
// testStruct()
testBitree()
}
Go
1
https://gitee.com/yemingzhi/GolangLearnPractice1.git
git@gitee.com:yemingzhi/GolangLearnPractice1.git
yemingzhi
GolangLearnPractice1
golang练习
2bf136849dce

搜索帮助