二叉排序树问题·······麻烦大家围观一小下
/*二叉排序树设计与实现*/
#include"iostream.h"
#include"stdlib.h"
typedef struct bstnode
{int key;
struct bstnode *lchild,*rchild;
}BSTNode,BSTree;
//查找关键字对应的数据
BSTNode *search(BSTree &bt,int k)
{int counter=0;
BSTree p;
p=bt;
while(p!=NULL)
{counter++;
if(p->key==key) return p;//查找成功返回
else
{if(key<p->key) p=p->lchild;//在左子树中查找
else p->rchild;//在右子树中查找
}
}
cout<<"search times ="<<counter<<endl;//输出次数
return 0;//查找失败
}
//
void Createtree(BSTree &root,int data[])
{BSTree p;//新建节点
BSTree current;//当前节点
BSTree parent;//父节点
int i;
for(i=0;i<n;i++)
{p=(BSTree)malloc(sizeof(BSTNode));//创建节点
p->key=data[i];
p->rchild=NULL;
p->lchild=NULL;
if(root==NULL) root=p;//根节点为空
else
{current=root;//目前的位置在根节点
while(current!=NULL)//当前节点为最低层结束循环
{parent=current;//记录父节点
if(current->key>=data[i])
current=current->lchild;
else
current=current->rchild;
}
//连起父与子节点
if(parent->key>data[i])
parent->lchild=p;
else parent->rchild=p;
}
}
}
void main()
{BSTree root=NULL;
BSTree p;
int data[n];
int key;
cout<<"intput the data of the tree:"<<endl;
for(int i=0;i<n;i++)
cin>>data[i];
Createtree(root,data);
cout<<"intput key:"<<endl;
cin>>key;
p=search(root,key);
if(p)
cout<<"the foinded key is:"<<p->key<<endl;
else cout<<"not found"<<endl;
}
出现了如下问题 麻烦大家解决一小下 不明白是哪里出了错
:\MSDev98\MyProjects\3\3.cpp(13) : error C2676: binary '!=' : 'struct bstnode' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\MSDev98\MyProjects\3\3.cpp(13) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
3.obj - 1 error(s), 0 warning(s)