#include <iostream>
#include<malloc.h>
using namespace std;
typedef struct BiNode{
char data;
struct BiNode *lchild,*rchild;
int ltag,rtag;//左右标志 为0指针 为1则是线索
}Node;
void createTree(Node *&Tree)
{//输入需要将二叉树补成满二叉树 ABD##E##CH### 或者 AB##C##
char c;
scanf("%c",&c);
if ('#' == c) //当遇到#时,令树的根节点为NULL,从而结束该分支的递归
Tree = NULL;
else
{
Tree=(Node *)malloc(sizeof(Node));
Tree->data = c;
Tree->ltag=0;
Tree->rtag=0;
createTree(Tree->lchild);
createTree(Tree->rchild);
}
}
//前序遍历
void preorder(Node *&Tree){
if(Tree){
printf("%c",Tree->data);
preorder(Tree->lchild);
preorder(Tree->rchild);
}
}
//中序遍历
void inorder(Node *&Tree){
if(Tree){
inorder(Tree->lchild);
printf("%c",Tree->data);
i
先序创建线索二叉树,并根据节点查找前驱后继
于 2021-09-20 11:17:26 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)