急!明天就要交作业了!

wolfzxq 2003-05-21 09:29:56
作业要求之一就是建立一棵二叉树。我的思路是依据广义表字符串S中建树。
但要编译时出现错误:
error C2440: '=' : cannot convert from 'struct BiTree *' to 'struct Bitree *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I:\backup\DataStructure\BTree\a.cpp(40) : error C2440: '=' : cannot convert from 'struct BiTree *' to 'struct Bitree *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

源代码如下:
#include <stdio.h>
#include <stdlib.h>

typedef struct BiTree
{
char data;
struct Bitree *lchild;
struct Bitree *rchild;
}BitreeNode;

int CreateBiTree(BitreeNode ** BT)
{
char *s,ch;
int top = -1,i=0,key;
BitreeNode *node[10],*p;
*BT = NULL;
scanf("请输入树的广义表表达式,例如“A(B(D,E),C)@”:");
scanf("%s",s);
ch = s[i++];
while(ch !='@')
{
switch(ch)
{
case '(':node[++top] = p;key = 1;break;
case ')':top--;break;
case ',':key = 2;break;
default: p = new BitreeNode;
p->data = ch;
p->lchild = p->rchild = NULL;
if(*BT == NULL)
*BT = p;
else
{
switch(key)
{
case 1:
node[top]->lchild = p;
break;
case 2:
node[top]->rchild = p;
break;
}
}
}
ch = s[i++];
}
}
void main()
{
BitreeNode *Node;
CreateBiTree(&Node);

}
请问这是为什么?
...全文
59 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
nicememory 2003-05-30
  • 打赏
  • 举报
回复
有点象basic里input的用法,呵呵
libiyan 2003-05-29
  • 打赏
  • 举报
回复
哈哈
wolfzxq 2003-05-28
  • 打赏
  • 举报
回复
呵呵。感谢各位的指导。
不知道yinjintao所说的明显被BASIC毒害是什么意思呢?
nicememory 2003-05-23
  • 打赏
  • 举报
回复
scanf("请输入树的广义表表达式,例如“A(B(D,E),C)@”:");
无语。。。。
明显被basic毒害了,:)
dragonlw 2003-05-23
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>

typedef struct BiTree
{
char data;
struct BiTree *lchild;
struct BiTree *rchild;
}BitreeNode;

void CreateBiTree(BitreeNode ** BT)
{
char *s= new char[20];
char ch;
int top = -1,i=0,key;
BitreeNode *node[10],*p=0;
*BT = NULL;
printf("请输入树的广义表表达式,例如“A(B(D,E),C)@”:\n");
scanf("%s",s);
ch = s[i++];
while(ch !='@')
{
switch(ch)
{
case '(':node[++top] = p;key = 1;break;
case ')':top--;break;
case ',':key = 2;break;
default: p = new BitreeNode;
p->data = ch;
p->lchild = p->rchild = NULL;
if(*BT == NULL)
*BT = p;
else
{
switch(key)
{
case 1:
node[top]->lchild = p;
break;
case 2:
node[top]->rchild = p;
break;
}
}
}
ch = s[i++];
}
}
void main()
{
BitreeNode *Node;
CreateBiTree(&Node);

}
呵呵,看看这回的吧
你那s指针没有分配空间,你就引用了。肯定引起内存的错误!
dragonlw 2003-05-23
  • 打赏
  • 举报
回复
scanf("请输入树的广义表表达式,例如“A(B(D,E),C)@”:");
这都什么错误啊!
dragonlw 2003-05-23
  • 打赏
  • 举报
回复
那只是简单的错误
都改过了 ,你也运行不了
可能是指针的错误!
Riemann 2003-05-22
  • 打赏
  • 举报
回复
呵呵,敲错是常有的事情,偶也经常这样,不过编译信息已经说得很清楚了呀!
BlueSky2008 2003-05-22
  • 打赏
  • 举报
回复
同意楼上的
nicememory 2003-05-22
  • 打赏
  • 举报
回复
呵呵,你自己代码打错了,同意楼上的
lymgf 2003-05-21
  • 打赏
  • 举报
回复
typedef struct BiTree
{
char data;
struct Bitree *lchild; //应为BiTree
struct Bitree *rchild; //应为BiTree
}BitreeNode;
ZhangYv 2003-05-21
  • 打赏
  • 举报
回复
没看你的程序,今晚我没时间了,你先参考:
http://expert.csdn.net/Expert/topic/1739/1739048.xml?temp=.1401941

33,028

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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