```go
//将二叉树转换成有序双向链表
func _ToSortLinkedList(cur *BinaryNode) {
var tmp = cur.Parant
if cur.Right != nil {
_ToSortLinkedList(cur.Right)
} else {
if tmp.Parant.Right == tmp && tmp.Parant != nil {
if tmp.Left == cur && tmp.Left != nil {
tmp.Parant.Right = cur
cur.Left = tmp.Parant //执行到这里的时候,对tmp.Parent 的影响影响到了递归外。
cur.Right = tmp
}
}
}
if cur.Left != nil {
_ToSortLinkedList(cur.Left)
} else {
if tmp.Parant.Left == tmp && tmp.Parant != nil {
if tmp.Right == cur && tmp.Right != nil {
tmp.Parant.Left = cur
cur.Right = tmp.Parant
cur.Left=tmp
}
}
}
}
```
更多评论
![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