求助:CXX0017:ERROR:symbol "" not found

Candy链上笔记 2016-04-25 05:42:10
VC6.0写二叉树程序,一直出现CXX0017:ERROR:symbol "" not found
求助,怎么解决啊
[code=cvoid InsertBST(BSTree *bst,int key)
{
BSTNod *s;
if ( bst == NULL)/*递归结束条件*/
{
s = (BSTree)malloc(sizeof(BSTNod)) ;//申请新的节点s
s->key = key;
s->lchild =NULL;
s->rchild =NULL;
bst = &s ;
}
else if (key < ( (*bst)->key) )
{
InsertBST(&((*bst)->lchild),key);/*将s插入左子树*/
}
else if (key > ((*bst)->key))
{
InsertBST(&((*bst)->rchild),key);/*将s插入右子树*/
}

}

void CreateBST(BSTree *bst)
{
int key;
bst = NULL;
scanf("%d",&key);
while (key != 0) /*输入0结束*/
{
InsertBST(bst,key);
scanf("%d",&key);
}
}

void InOrder(BSTree *bst)
{
if (bst != NULL)
{
InOrder(&(*bst)->lchild);
printf("%d ",(*bst)->key);
InOrder(&(*bst)->rchild);
}
}


int main()
{
BSTree *root = NULL;
CreateBST(root);
InOrder(root);
return 0;
}][/code]
...全文
308 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Candy链上笔记 2016-04-27
  • 打赏
  • 举报
回复
引用 8 楼 lm_whales 的回复:
传递引用的版本,代码比传递指针的干净多了 而且也符合我们的思维逻辑 传递指针,要额外迁就指针的写法, 过多关注与实现逻辑, 而不是问题逻辑。 直接把 算法伪代码,改成程序,就是二叉树的插入,创建和遍历了 遍历不需要指针的指针,也不需要传递引用, 因为我们只是使用节点的数据,并不打算改变节点的值。
typedef int keytype;
typedef struct BinTree{
    keytype key;
    struct BinTree *lchild,*rchild;
} *BSTree,BSTNod ;

void InsertBST(BSTree &bst,int key)
{
BSTNod *s;
if ( bst == NULL)/*递归结束条件*/
{
s = (BSTree)malloc(sizeof(BSTNod)) ;//申请新的节点s
s->key = key;
s->lchild =NULL;
s->rchild =NULL;
bst = s ;

}
else if (key <  bst->key )
{
InsertBST(bst->lchild,key);/*将s插入左子树*/

}
else if (key > bst->key)
{
InsertBST(bst->rchild,key);/*将s插入右子树*/
}

}

void CreateBST(BSTree& bst)
{
int key;
bst = NULL;
scanf("%d",&key);
while (key != 0)        /*输入0结束*/
{
InsertBST(bst,key);
scanf("%d",&key);
}
}

void InOrder(BSTree bst)
{
if (bst != NULL)
{
InOrder(bst->lchild);
printf("%d ",bst->key);
InOrder(bst->rchild);
}
}
//添加一个释放所有节点的代码
void Release(BSTree & root){
     if(root){
          Release (root->lchild);
          Release (root->rchild);
          free(root);  
     }
}

int main()
{
BSTree root = NULL; ///直接定义为节点(指针)类型即可
CreateBST(root);
InOrder(root);
Release(root)
return 0;
}
谢谢谢谢!
lm_whales 2016-04-26
  • 打赏
  • 举报
回复
传递引用的版本,代码比传递指针的干净多了 而且也符合我们的思维逻辑 传递指针,要额外迁就指针的写法, 过多关注与实现逻辑, 而不是问题逻辑。 直接把 算法伪代码,改成程序,就是二叉树的插入,创建和遍历了 遍历不需要指针的指针,也不需要传递引用, 因为我们只是使用节点的数据,并不打算改变节点的值。
typedef int keytype;
typedef struct BinTree{
    keytype key;
    struct BinTree *lchild,*rchild;
} *BSTree,BSTNod ;

void InsertBST(BSTree &bst,int key)
{
BSTNod *s;
if ( bst == NULL)/*递归结束条件*/
{
s = (BSTree)malloc(sizeof(BSTNod)) ;//申请新的节点s
s->key = key;
s->lchild =NULL;
s->rchild =NULL;
bst = s ;

}
else if (key <  bst->key )
{
InsertBST(bst->lchild,key);/*将s插入左子树*/

}
else if (key > bst->key)
{
InsertBST(bst->rchild,key);/*将s插入右子树*/
}

}

void CreateBST(BSTree& bst)
{
int key;
bst = NULL;
scanf("%d",&key);
while (key != 0)        /*输入0结束*/
{
InsertBST(bst,key);
scanf("%d",&key);
}
}

void InOrder(BSTree bst)
{
if (bst != NULL)
{
InOrder(bst->lchild);
printf("%d ",bst->key);
InOrder(bst->rchild);
}
}
//添加一个释放所有节点的代码
void Release(BSTree & root){
     if(root){
          Release (root->lchild);
          Release (root->rchild);
          free(root);  
     }
}

int main()
{
BSTree root = NULL; ///直接定义为节点(指针)类型即可
CreateBST(root);
InOrder(root);
Release(root)
return 0;
}
lm_whales 2016-04-26
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
int key;
struct node *lchild,*rchild;
}BSTNod,*BSTree;

void InsertBST(BSTree *bst,int key)
{
	BSTNod *s;
	if ( *bst == NULL)/*递归结束条件*/
	{
		s = (BSTree)malloc(sizeof(BSTNod)) ;//申请新的节点s
		s->key = key;
		s->lchild =NULL;
		s->rchild =NULL;
		*bst = s ; //这地方修改一下,不应该给 bst 赋 地址值
                               //1)局部变量地址不能储存,
                               //2)bst 是节点(指针)的地址,我们要改变的是节点(指针)的值
	}
	else if (key < ( (*bst)->key) )
	{
		InsertBST(&((*bst)->lchild),key);/*将s插入左子树*/
	}
	else if (key > ((*bst)->key))
	{
		InsertBST(&((*bst)->rchild),key);/*将s插入右子树*/
	}

}

void CreateBST(BSTree *bst)
{
	int key;
        ///bst = NULL; ///不可给节点(指针)的地址赋值
	*bst = NULL; /// 应该给节点(指针)赋值,
	scanf("%d",&key);
	while (key != 0)        /*输入0结束*/
	{
		InsertBST(bst,key);
		scanf("%d",&key);
	}
}

void InOrder(BSTree bst) ///遍历不修改节点本身,直接传递跟指针就可以了。
{
	if (bst != NULL)
	{
		InOrder(bst->lchild);  //直接传递指针
		printf("%d ",bst->key); //直接指向
		InOrder(bst->rchild); //直接传递指针
	}
}


int main()
{
	BSTree root = NULL;
	CreateBST(&root);
	InOrder(root);
	return 0;
}
如此修改一下,就好了 其实如果是C++可以传递引用 这样就不必传递节点的指针了
Candy链上笔记 2016-04-25
  • 打赏
  • 举报
回复
引用 5 楼 qq423399099 的回复:
可以编译啊。。楼主是不是把最后的][/code]没有删掉 楼主复制粘贴过去试试,有问题再发上来

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
int key;
struct node *lchild,*rchild;
}BSTNod,*BSTree;

void InsertBST(BSTree *bst,int key)
{
	BSTNod *s;
	if ( bst == NULL)/*递归结束条件*/
	{
		s = (BSTree)malloc(sizeof(BSTNod)) ;//申请新的节点s
		s->key = key;
		s->lchild =NULL;
		s->rchild =NULL;
		bst = &s ;
	}
	else if (key < ( (*bst)->key) )
	{
		InsertBST(&((*bst)->lchild),key);/*将s插入左子树*/
	}
	else if (key > ((*bst)->key))
	{
		InsertBST(&((*bst)->rchild),key);/*将s插入右子树*/
	}

}

void CreateBST(BSTree *bst)
{
	int key;
	bst = NULL;
	scanf("%d",&key);
	while (key != 0)        /*输入0结束*/
	{
		InsertBST(bst,key);
		scanf("%d",&key);
	}
}

void InOrder(BSTree *bst)
{
	if (bst != NULL)
	{
		InOrder(&(*bst)->lchild);
		printf("%d ",(*bst)->key);
		InOrder(&(*bst)->rchild);
	}
}


int main()
{
	BSTree *root = NULL;
	CreateBST(root);
	InOrder(root);
	return 0;
}
是可以编译,但执行有问题。root指针那一块设置断点的话,就会显示XX0017:ERROR:symbol "" not found
小灸舞 版主 2016-04-25
  • 打赏
  • 举报
回复
可以编译啊。。楼主是不是把最后的][/code]没有删掉 楼主复制粘贴过去试试,有问题再发上来

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
int key;
struct node *lchild,*rchild;
}BSTNod,*BSTree;

void InsertBST(BSTree *bst,int key)
{
	BSTNod *s;
	if ( bst == NULL)/*递归结束条件*/
	{
		s = (BSTree)malloc(sizeof(BSTNod)) ;//申请新的节点s
		s->key = key;
		s->lchild =NULL;
		s->rchild =NULL;
		bst = &s ;
	}
	else if (key < ( (*bst)->key) )
	{
		InsertBST(&((*bst)->lchild),key);/*将s插入左子树*/
	}
	else if (key > ((*bst)->key))
	{
		InsertBST(&((*bst)->rchild),key);/*将s插入右子树*/
	}

}

void CreateBST(BSTree *bst)
{
	int key;
	bst = NULL;
	scanf("%d",&key);
	while (key != 0)        /*输入0结束*/
	{
		InsertBST(bst,key);
		scanf("%d",&key);
	}
}

void InOrder(BSTree *bst)
{
	if (bst != NULL)
	{
		InOrder(&(*bst)->lchild);
		printf("%d ",(*bst)->key);
		InOrder(&(*bst)->rchild);
	}
}


int main()
{
	BSTree *root = NULL;
	CreateBST(root);
	InOrder(root);
	return 0;
}
Candy链上笔记 2016-04-25
  • 打赏
  • 举报
回复
引用 2 楼 lm_whales 的回复:
没问题啊?你的类型定义呢?
哦哦,这里。 typedef struct node { int key; struct node *lchild,*rchild; }BSTNod,*BSTree;
Candy链上笔记 2016-04-25
  • 打赏
  • 举报
回复
引用 1 楼 qq423399099 的回复:
楼主代码贴全,别说你已经贴全了噢
sorry. typedef struct node { int key; struct node *lchild,*rchild; }BSTNod,*BSTree;
lm_whales 2016-04-25
  • 打赏
  • 举报
回复
没问题啊?你的类型定义呢?
小灸舞 版主 2016-04-25
  • 打赏
  • 举报
回复
楼主代码贴全,别说你已经贴全了噢

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧