二叉树递归的时候,指针被改了造成了无限循环,怎么规避呀

fwhez · · 1048 次点击
更多评论
![bt.png](https://static.studygolang.com/180620/66d0f1ab16a9a469b5ab0ec3f0b3e7dd.png)
#1
最后还是决定重新开辟空间…… ```go func (bt *BinaryNode) ToAscLinkedList() (*SortedLinkedList, error) { var sum int bt.GetNodesNum(&sum) var rs = make([]interface{}, sum) var flag = 0 bt.ToAscArray(&rs, &flag) head := New(rs[0]) tail := head var tmp *BinaryNode for i := 1; i < len(rs); i++ { tmp = New(rs[i]) tail.Right = tmp tmp.Left = tail tail = tmp } return &SortedLinkedList{head}, nil } ```
#2