#2
CEO小贼2013-11-28 16:22
--------------------Configuration: 3 - Win32 Debug--------------------
Compiling... 3.cpp E:\3\3.cpp(15) : error C2227: left of '->key' must point to class/struct/union E:\3\3.cpp(16) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(16) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(17) : error C2440: '=' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(23) : error C2227: left of '->key' must point to class/struct/union E:\3\3.cpp(24) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(26) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(29) : error C2227: left of '->key' must point to class/struct/union E:\3\3.cpp(30) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(32) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(39) : error C2440: '=' : cannot convert from 'struct BiTNode *' to 'struct BiTNode ** ' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(44) : error C2227: left of '->key' must point to class/struct/union E:\3\3.cpp(44) : error C2440: 'return' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(47) : error C2227: left of '->key' must point to class/struct/union E:\3\3.cpp(48) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(50) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(55) : error C2440: 'return' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(61) : error C2227: left of '->key' must point to class/struct/union E:\3\3.cpp(62) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(62) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(65) : error C2440: '=' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(67) : error C2440: '=' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(72) : error C2440: '=' : cannot convert from 'struct BiTNode *' to 'struct BiTNode ** ' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast E:\3\3.cpp(73) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(76) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(78) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(81) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(86) : error C2227: left of '->lchild' must point to class/struct/union E:\3\3.cpp(87) : error C2227: left of '->rchild' must point to class/struct/union E:\3\3.cpp(87) : fatal error C1903: unable to recover from previous error(s); stopping compilation 执行 cl.exe 时出错. 3.obj - 1 error(s), 0 warning(s) 这些错误什么意思? |
#include<stdio.h>
#include<stdlib.h>
#define N 10
typedef struct BiTNode{
int key;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
void CreateBiT(BiTree &T,int data[])
{
BiTree *current,*father,*p;
int i;
for(i=0;i<N;i++)
{
p=(BiTree *)malloc(sizeof(BiTNode));
p->key=data[i];
p->lchild=p->rchild=NULL;
if(T==NULL) T=p;
else
{
while(current!=NULL)
{
father=current;
if(current->key>data[i])
current=current->lchild;
else
current=current->rchild;
}
if(father->key>data[i])
father->lchild=p;
else
father->rchild=p;
}
}
}
BiTree SearchBiT(BiTree &T,int key)
{
BiTree *p,*father;
p=T;
int counter=0;
while(p!=NULL)
{
father=p;
if(p->key==key) return p;
else
{
if(p->key>key)
p=p->lchild;
else
p=p->rchild;
}
counter++;
}
printf("查找的次数为%d",counter);
return father;
}
void InsertBiT(BiTree &p,int key)
{
BiTree *s;
s=(BiTree *)malloc(sizeof(BiTNode));
s->key=key;
s->lchild=s->rchild=NULL;
if(p->key>key)
p->lchild=s;
else
p->rchild=s;
}
void DeleteBST(BiTree &q)
{
BiTree *p,*m,*n;
p=q;
if(!p->rchild)
{
m=p;
p=p->lchild;
}
else if(!p->lchild)
{
m=p;
p=p->rchild;
}
else
{
m=p;n=p->lchild;
while(n->rchild)
{
m=n;n=n->rchild;
}
p->key=n->key;
if(m!=p)
m->lchild=n->lchild;
else
m->lchild=n->lchild;
}
}
void main()
{
BiTree *T,*p,*q;
int i,key,num;
int data[N];
printf("请按数字空格的格式依次输入是个整数\n");
for(i=0;i<=N;i++)
{scanf("%d",&data[i]);}
CreateBiT(T,data);
printf("请输入待查询的整数\n");
scanf("%d",&key);
p=SearchBiT(T,key);
if(p->key==key) printf("您要查找的数据为%d",p->key);
else
{InsertBiT(p,key);
printf("没有找到该数据,已帮您插入到二叉排序树\n");
}
printf("请输入待删除的数据\n");
scanf("%d",&num);
q=SearchBiT(T,num);
if(q->key==num) DeleteBiT(q);
else
printf("您输入的数据有误");
}