帮忙看看怎么改
如何修改一下代码,使其能线索化二叉树:(8)19((5)11((2)6(4)))// a.cpp : Defines the entry point for the console application.
//
// tbt.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
typedef struct node //二叉树结点的结构
{
char ch;
struct node *lchild, *rchild;
int ltag, rtag;
}Bnode;
Bnode * InitRoot()
{
Bnode * root;
root = (Bnode *) malloc(sizeof(Bnode));
root->lchild = NULL;
root->rchild = NULL;
return root;
}
Bnode * CreateBiTree(Bnode ** T)
{
char ch;
fflush(stdin);
ch = getchar();
if (ch=='#'){
* T = NULL;
return NULL;
}
else{
Bnode * temp;
if (!(temp= (Bnode *)malloc(sizeof(Bnode)))) return NULL;
temp->ch= ch;
* T = temp;
CreateBiTree(&(temp->lchild));
CreateBiTree(&(temp->rchild));
}
return *T;
}
void InOrder(Bnode * root)
{
if (root == NULL) return;
InOrder(root->lchild);
printf("%c ", root->ch);
InOrder(root->rchild);
}
void Destory(Bnode ** root)
{
if ((*root) != NULL && ((*root)->lchild != NULL))
Destory(&((*root)->lchild));
if ((*root) != NULL && ((*root)->lchild != NULL))
Destory(&((*root)->lchild));
free(root);
}
void InThread(Bnode * current, Bnode ** pre)
{
if (current != NULL){
InThread(current->lchild,pre);
if (current->lchild == NULL)
{
current->ltag = 1;
current->lchild = * pre;
}
else
current->ltag = 0;
if (current->rchild != NULL) current->rtag = 0;
if ((*pre)->rchild == NULL)
{
(*pre)->rtag = 1;
(*pre)->rchild = current;
}
else current->rtag = 0;
(*pre) = current;
InThread(current->rchild, pre);
}
}
void CreateInThread(Bnode ** root)
{
Bnode * t = * root;
Bnode *current, *pre;
*root = (Bnode *)malloc(sizeof(Bnode));
pre = * root;
if (t==NULL)
{
(*root)->ltag = 0;
(*root)->rtag = 1;
(*root)->lchild = *root;
(*root)->rchild = *root;
}
else
{
current = t;
(*root)->lchild = t;
(*root)->ltag = 0;
InThread(current, &pre);
pre->rchild = *root;
pre->rtag = 1;
(*root)->rchild = pre;
(*root)->rtag = 1;
}
}
int main(int argc, char * argv[])
{
Bnode * root, * head;
CreateBiTree(&root);
InOrder(root);
CreateInThread(&root);
//Destory(&root);
printf("Hello World!\n");
return 0;
}