<pre name="code" class="cpp">/*全局变量,始终指向刚刚访问的结点*/ btree_node* p = NULL; void thread_via_tree(btree_node* root) { if(root != NULL) { /*p保留了其前驱元素*/ if(p != NULL) { p->left = root; p = NULL; } /*全局变量,始终指向刚刚访问的结点*/ btree_node* p = NULL; void thread_via_tree(btree_node* root) { if(root != NULL) { /*p保留了其前驱元素*/ if(p != NULL) { p->left = root; p = NULL; } /*此节点的左孩子指针域为空, 记录此节点的指针域准备指向其后继元素 保留到下次进入此函数的结点,即是其后继元素*/ if(root->left == NULL) { p = root; } thread_via_tree(root->left); thread_via_tree(root->right); } }
实现代码: void thread_via_list(btree_node* root, SeqList* list) { if((root != NULL) && (list != NULL)) { SeqList_Insert(list, (SeqListNode*)root, SeqList_Length(list)); thread_via_list(root->left, list); thread_via_list(root->right, list); } }
原文:http://blog.csdn.net/u011467781/article/details/45271505