#include <iostream> using namespace std; //创建树结构 typedef struct node { int data; struct node *ltree,*rtree; }*BitTree,bitTree; //创建树函数 void creat_tree(BitTree &tree); void mid_travel(BitTree tree,BitTree &bsTree); int main() { BitTree pTree; BitTree bsTree=NULL; cout<<"please input data of the tree:"<<endl; creat_tree(pTree); mid_travel(pTree,bsTree); //输出节点信息 while (bsTree) { cout<<bstree->data<<" "; bsTree=bsTree->ltree; } system("pause"); return 0; } void creat_tree(BitTree &tree) { int data; cin>>data; //退出条件 if (data==0) { tree=NULL; return; } else { tree=new bitTree; if (tree==NULL) { exit(0); } tree->data=data; //创建左子树 creat_tree(tree->ltree); //创建右子树 creat_tree(tree->rtree); } } //中序访问 void mid_travel(BitTree tree,BitTree &bsTree) { if (tree==NULL) { return ; } //记录当前节点 BitTree pro_node=tree; if (tree->ltree!=NULL) { mid_travel(tree->ltree,bsTree); } //通过bstree与pro_node实现双联表的转换 pro_node->ltree=bsTree; if (bsTree!=NULL) { bsTree->rtree=pro_node; } bsTree=pro_node; //访问右分支 if (tree->rtree!=NULL) { mid_travel(pro_node->rtree,bsTree); } return ; } </bstree-></iostream>