`#include <stdlib.h> #include <stdio.h>  typedef struct TNode {     int value;     TNode* lchild;     TNode* rchild; }TNode,*BTree;  //二叉树转换为双向链表 TNode* TreeToList(BTree tree,TNode* &lastNode) {     TNode* head;     //若树为空，返回空     if (tree == NULL)      {         lastNode = NULL;         return NULL;     }     //若无左子树，则该根节点为链表的头结点     if (tree->lchild==NULL)     {         head = tree;     }     //若有左子树，递归调用转换函数将左子树转换为双向链表     //左子树转换所得链表的头结点是整个树的头结点     //左子树链表的尾结点与根节点相邻     else     {         head = TreeToList(tree->lchild,lastNode);         tree->lchild = lastNode;         lastNode->rchild = tree;     }     //若无右子树，则该根节点为链表的尾结点     if (tree->rchild==NULL)     {         lastNode = tree;      }     //若有右子树，递归调用转换函数将左子树转换为双向链表     //右子树转换所得链表的尾结点是整个树的尾结点     //右子树链表的头结点与根节点相邻     else     {         tree->rchild = TreeToList(tree->rchild,lastNode);         tree->rchild->lchild = tree;     }     return head; }  int main() {     BTree tree = (BTree)malloc(sizeof(TNode));     tree->value = 4;     tree->lchild = (TNode*)malloc(sizeof(TNode));     tree->lchild->value = 2;     tree->lchild->lchild = (TNode*)malloc(sizeof(TNode));     tree->lchild->lchild->value = 1;     tree->lchild->lchild->lchild = NULL;     tree->lchild->lchild->rchild = NULL;     tree->lchild->rchild = (TNode*)malloc(sizeof(TNode));     tree->lchild->rchild->value = 3;     tree->lchild->rchild->lchild = NULL;     tree->lchild->rchild->rchild = NULL;     tree->rchild = (TNode*)malloc(sizeof(TNode));     tree->rchild->value = 6;     tree->rchild->lchild = (TNode*)malloc(sizeof(TNode));     tree->rchild->lchild->value = 5;     tree->rchild->lchild->lchild = NULL;     tree->rchild->lchild->rchild = NULL;     tree->rchild->rchild = NULL;          TNode* lastNode;     TNode* listHead = TreeToList(tree,lastNode);     TNode* node = listHead;     while(node)     {         printf("%d ",node->value);         node = node->rchild;     }     printf("\n");      return 0; } `