[英]binary tree insertion
在以下代码中,我遇到了编译错误:c2227:-> left的左边必须指向类/结构/联合/泛型类型。 任何帮助如何解决此问题; 我正在尝试插入二叉树中。
typedef struct bnode{
int key;
struct bnode* left;
struct bnode* right;
}BNODE;
void printKeysReverse(BNODE* current);
void inorder(BNODE* current);
void insert(BNODE **root,int key);
int main(void){
BNODE* root=NULL;
insert(&root,27);
insert(&root,59);
insert(&root,21);
insert(&root,38);
insert(&root,54);
insert(&root,63);
insert(&root,8);
insert(&root,70);
insert(&root,15);
}
void insert(BNODE **root, int val){
BNODE *newnode;
newnode=(BNODE*)malloc(sizeof(BNODE));
newnode->right=NULL;
newnode->left=NULL;
if ((*root)==NULL){
*root=newnode;
(*root)->key=val;
return;
}
if (val<(*root)->key) insert((&root)->left,val);
else insert((&root)->right,val);
}//end
(&root)-> left&root不是一个结点*
void insert(BNODE **root, int val){
BNODE *newnode;
newnode= malloc(sizeof *newnode);
newnode->right=NULL;
newnode->left=NULL;
newnode->key=val;
while (*root){
if (val < (*root)->key) root = &(*root)->left;
else root = &(*root)->right;
}
*root=newnode;
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.