这是一个关于线索二叉树的C程序,有点小问题
时间:2011-12-09
来源:互联网
这个程序里函数:void InOrderThreading(BiThrTree *Thrt,BiThrTree T)中的
(*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode));出错,
错误信息为:error C2065: 'Thrt' : undeclared identifier
以下为源代码:
C/C++ code
(*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode));出错,
错误信息为:error C2065: 'Thrt' : undeclared identifier
以下为源代码:
C/C++ code
#include<stdio.h> #include<stdlib.h> #define OK 1 #define ERROR 0 #define OVERFLOW -1 #define TRUE 1 #define FALSE 0 typedef char TElemType; /** 二叉树的二叉线索存储表示 */ typedef enum{Link,Thread} PointerTag; /* Link(0):指针,Thread(1):线索**/ typedef struct BiThrNode { TElemType data; struct BiThrNode *lchild,*rchild; PointerTag LTag,RTag; }BiThrNode,* BiThrTree; /** 二叉树的二叉线索存储的基本操作 */ void CreatBiThrTree(BiThrTree *T) { /*按先序输入线索二叉树中的结点的值,构造二叉树-**/ TElemType ch; ch = getchar(); //获取从键盘输入的字符 getchar(); //消除键盘回车屏蔽 if(ch = '#') *T = NULL; else { *T = (BiThrTree)malloc(sizeof(BiThrNode)); /** 生成根节点(先序)*/ if(!*T) exit(OVERFLOW); //内存分配失败 (*T)->data = ch; //根节点赋值 CreatBiThrTree(&(*T)->lchild); //递归构造左子树 if((*T)->lchild) //有左孩子 (*T)->LTag = Link; //给左标志赋值(指针) CreatBiThrTree(&(*T)->rchild); //递归构造右子树 if((*T)->rchild) //有右孩子 (*T)->RTag = Link; //给右标志赋值(指针) } } BiThrTree pre; /** 全局变量,始终指向刚刚访问的结点*/ void InThreading(BiThrTree p) { /** 通过中序遍历进行中序线索化,线索化之后pre指向最后一个结点*/ if(p) { InThreading(p->lchild); /* 递归左子树线索化 */ if(!p->lchild) /* 没有左孩子*/ { p->LTag = Thread; /** 左标志为线索(前驱)*/ p->lchild = pre; /** 左孩子指针指向前驱 */ } if(!pre->rchild) /**前驱没有右孩子*/ { pre->RTag = Thread; /** 前驱的右标志为线索 */ pre->rchild = p; /** 前驱右孩子指针指向其后继(当前结点p)*/ } pre = p; /** 保持pre指向p的前驱*/ InThreading(p->rchild); /**递归右子树线索化*/ } } void InOrderThreading(BiThrTree *Thrt,BiThrTree T) { /** 中序遍历二叉树T,并将其中序线索化,Thrt指向头结点 */ (*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode)); if(!(*Thrt)) /**生成头结点不成功*/ exit(OVERFLOW); (*Thrt)->LTag=Link; /**建头结点,左标志为指针*/ (*Thrt)->RTag=Thread; /**右标志为线索*/ (*Thrt)->rchild=*Thrt; /**右指针回指*/ if(!T) /* 若二叉树空,则左指针回指**/ (*Thrt)->lchild=(*Thrt); else { (*Thrt)->lchild=T; /**头结点的指针指向根结点*/ pre=(*Thrt); /** pre(前驱)的初值指向头结点*/ InTreading(T); /** 中序遍历進行中序线索化,pre指向中序遍历的最後一個结点 */ pre->rchild=(*Thrt); /**最后一个结点的右指针指向头结点*/ pre->RTag=Thread; /**最后一个结点的右标志为线索*/ (*Thrt)->rchild=pre; /**头结点的右指针指向中序遍历的最后一个结点*/ } }
作者: CST08055 发布时间: 2011-12-09
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define TRUE 1
#define FALSE 0
typedef char TElemType;
/** 二叉树的二叉线索存储表示 */
typedef enum{Link,Thread} PointerTag; /* Link(0):指针,Thread(1):线索**/
typedef struct BiThrNode
{
TElemType data;
struct BiThrNode *lchild,*rchild;
PointerTag LTag,RTag;
}BiThrNode,* BiThrTree;
/** 二叉树的二叉线索存储的基本操作 */
void CreatBiThrTree(BiThrTree *T)
{
/*按先序输入线索二叉树中的结点的值,构造二叉树-**/
TElemType ch;
ch = getchar(); //获取从键盘输入的字符
getchar(); //消除键盘回车屏蔽
if(ch = '#')
*T = NULL;
else
{
*T = (BiThrTree)malloc(sizeof(BiThrNode)); /** 生成根节点(先序)*/
if(!*T)
exit(OVERFLOW); //内存分配失败
(*T)->data = ch; //根节点赋值
CreatBiThrTree(&(*T)->lchild); //递归构造左子树
if((*T)->lchild) //有左孩子
(*T)->LTag = Link; //给左标志赋值(指针)
CreatBiThrTree(&(*T)->rchild); //递归构造右子树
if((*T)->rchild) //有右孩子
(*T)->RTag = Link; //给右标志赋值(指针)
}
}
BiThrTree pre; /** 全局变量,始终指向刚刚访问的结点*/
void InThreading(BiThrTree p)
{ /** 通过中序遍历进行中序线索化,线索化之后pre指向最后一个结点*/
if(p)
{
InThreading(p->lchild); /* 递归左子树线索化 */
if(!p->lchild) /* 没有左孩子*/
{
p->LTag = Thread; /** 左标志为线索(前驱)*/
p->lchild = pre; /** 左孩子指针指向前驱 */
}
if(!pre->rchild) /**前驱没有右孩子*/
{
pre->RTag = Thread; /** 前驱的右标志为线索 */
pre->rchild = p; /** 前驱右孩子指针指向其后继(当前结点p)*/
}
pre = p; /** 保持pre指向p的前驱*/
InThreading(p->rchild); /**递归右子树线索化*/
}
}
void InOrderThreading(BiThrTree *Thrt,BiThrTree T)
{
/** 中序遍历二叉树T,并将其中序线索化,Thrt指向头结点 */
(*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode));
if(!(*Thrt)) /**生成头结点不成功*/
exit(OVERFLOW);
(*Thrt)->LTag=Link; /**建头结点,左标志为指针*/
(*Thrt)->RTag=Thread; /**右标志为线索*/
(*Thrt)->rchild=*Thrt; /**右指针回指*/
if(!T) /* 若二叉树空,则左指针回指**/
(*Thrt)->lchild=(*Thrt);
else
{
(*Thrt)->lchild=T; /**头结点的指针指向根结点*/
pre=(*Thrt); /** pre(前驱)的初值指向头结点*/
InThreading(T);/** InTreading(T); 中序遍历進行中序线索化,pre指向中序遍历的最後一個结点 */
pre->rchild=(*Thrt); /**最后一个结点的右指针指向头结点*/
pre->RTag=Thread; /**最后一个结点的右标志为线索*/
(*Thrt)->rchild=pre; /**头结点的右指针指向中序遍历的最后一个结点*/
}
}
上面是给你改的,但是是这个错误在VS2010上面
无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
fatal error LNK1120: 1 个无法解析的外部命令
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define TRUE 1
#define FALSE 0
typedef char TElemType;
/** 二叉树的二叉线索存储表示 */
typedef enum{Link,Thread} PointerTag; /* Link(0):指针,Thread(1):线索**/
typedef struct BiThrNode
{
TElemType data;
struct BiThrNode *lchild,*rchild;
PointerTag LTag,RTag;
}BiThrNode,* BiThrTree;
/** 二叉树的二叉线索存储的基本操作 */
void CreatBiThrTree(BiThrTree *T)
{
/*按先序输入线索二叉树中的结点的值,构造二叉树-**/
TElemType ch;
ch = getchar(); //获取从键盘输入的字符
getchar(); //消除键盘回车屏蔽
if(ch = '#')
*T = NULL;
else
{
*T = (BiThrTree)malloc(sizeof(BiThrNode)); /** 生成根节点(先序)*/
if(!*T)
exit(OVERFLOW); //内存分配失败
(*T)->data = ch; //根节点赋值
CreatBiThrTree(&(*T)->lchild); //递归构造左子树
if((*T)->lchild) //有左孩子
(*T)->LTag = Link; //给左标志赋值(指针)
CreatBiThrTree(&(*T)->rchild); //递归构造右子树
if((*T)->rchild) //有右孩子
(*T)->RTag = Link; //给右标志赋值(指针)
}
}
BiThrTree pre; /** 全局变量,始终指向刚刚访问的结点*/
void InThreading(BiThrTree p)
{ /** 通过中序遍历进行中序线索化,线索化之后pre指向最后一个结点*/
if(p)
{
InThreading(p->lchild); /* 递归左子树线索化 */
if(!p->lchild) /* 没有左孩子*/
{
p->LTag = Thread; /** 左标志为线索(前驱)*/
p->lchild = pre; /** 左孩子指针指向前驱 */
}
if(!pre->rchild) /**前驱没有右孩子*/
{
pre->RTag = Thread; /** 前驱的右标志为线索 */
pre->rchild = p; /** 前驱右孩子指针指向其后继(当前结点p)*/
}
pre = p; /** 保持pre指向p的前驱*/
InThreading(p->rchild); /**递归右子树线索化*/
}
}
void InOrderThreading(BiThrTree *Thrt,BiThrTree T)
{
/** 中序遍历二叉树T,并将其中序线索化,Thrt指向头结点 */
(*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode));
if(!(*Thrt)) /**生成头结点不成功*/
exit(OVERFLOW);
(*Thrt)->LTag=Link; /**建头结点,左标志为指针*/
(*Thrt)->RTag=Thread; /**右标志为线索*/
(*Thrt)->rchild=*Thrt; /**右指针回指*/
if(!T) /* 若二叉树空,则左指针回指**/
(*Thrt)->lchild=(*Thrt);
else
{
(*Thrt)->lchild=T; /**头结点的指针指向根结点*/
pre=(*Thrt); /** pre(前驱)的初值指向头结点*/
InThreading(T);/** InTreading(T); 中序遍历進行中序线索化,pre指向中序遍历的最後一個结点 */
pre->rchild=(*Thrt); /**最后一个结点的右指针指向头结点*/
pre->RTag=Thread; /**最后一个结点的右标志为线索*/
(*Thrt)->rchild=pre; /**头结点的右指针指向中序遍历的最后一个结点*/
}
}
上面是给你改的,但是是这个错误在VS2010上面
无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
fatal error LNK1120: 1 个无法解析的外部命令
作者: zhutou100hao 发布时间: 2011-12-09
恩,这是一个错误,但是前面的:void InOrderThreading(BiThrTree *Thrt,BiThrTree T)中的
:(*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode));出错,
:错误信息为:error C2065: 'Thrt' : undeclared identifier
错误信息还在
:(*Thrt) = (BiThrTree)malloc(sizeof(BiThrNode));出错,
:错误信息为:error C2065: 'Thrt' : undeclared identifier
错误信息还在
作者: CST08055 发布时间: 2011-12-10
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28