排序二叉树转变为有序双向链表
要点:
1.直接改变树的结构
2.排序二叉树在中序遍历的时候是有序的
3.双向链表,需要前后两个指针(可以将Tree的节点作为链表节点)
代码实现:中序的递归实现
void ToList(Tree* pTree ,Tree** pHead,Tree** pEnd ) { if(pTree == NULL ) return; ToList(pTree->pleft,pHead,pEnd); if(*pHead == NULL) { *pHead = pTree; *pEnd = pTree; } else { (*pEnd)->pright = pTree; pTree->pleft = *pEnd; } (*pEnd) = pTree; ToList(pTree->pright,pHead,pEnd); }