标签:int lan values Golan func ret val 思路 turn
思路不太好理解,请用断点
package main import "fmt" type tree struct { value int left, right *tree } func Sort(values []int) { var root *tree for _, v := range values { root = add(root, v) } appendValues(values[:0], root) } func appendValues(values []int, t *tree) []int { if t != nil { values = appendValues(values, t.left) values = append(values, t.value) values = appendValues(values, t.right) } return values } func add(t *tree, value int) *tree { if t == nil { t = new(tree) t.value = value return t } if value < t.value { t.left = add(t.left, value) } else { t.right = add(t.right, value) } return t } func main() { var list = []int{5, 1, 8, 3, 6} fmt.Println(list) Sort(list) fmt.Println(list) }
标签:int lan values Golan func ret val 思路 turn
原文地址:https://www.cnblogs.com/xiangxiaolin/p/11901691.html