我不会错过任何}或;那么为什么我得到这个错误? 实际错误显示“输入结束时的预期声明或声明”。C错误:在输入结束时的预期声明或陈述c
bool search(struct bstnode* root,int data) {
if(root == NULL) {
return false;
}
else if(root->data == data) {
return true;
}
else if(data <= root->data) {
return Search(root->left,data);
}
else {
return Search(root->right,data);
}
}//getting error at this point
问题的完整代码...二进制搜索树,在搜索功能(下面)中获取错误。提前致谢。
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define BOOL bool
struct bstnode{
int data;
struct bstnode* left;
struct bstnode* right;
};
struct bstnode* insert(struct bstnode* root,int data);
//struct bstnode* root=NULL;
bool Search(struct bstnode* root,int data);
int main()
{
struct bstnode* root = NULL;
root = Insert(root,15);
root = Insert(root,10);
root = Insert(root,20);
root = Insert(root,25);
root = Insert(root,8);
root = Insert(root,12);
int number;
printf("Enter number be searched\n");
scanf("%d",&number);
//If number is found, print "FOUND"
search(root,number);
if(search(root,number) == true) printf("Found\n");
else printf("Not Found\n");
}
struct bstnode* getnewnode(int data)
{
struct bstnode* newnode=(struct bstnode*)malloc(sizeof(struct bstnode*));
newnode=(struct bstnode*)malloc(sizeof(struct bstnode*));
newnode->data=data;
newnode->left=NULL;//Initially Null, not pointing at anything
newnode->right=NULL;//Initially NULL, not pointing at anything
return newnode; //Return address of New Node
}
struct bstnode* insert(struct bstnode* root,int data) {
{
if(root==NULL)//condition 1, tree is empty.
{
root=getnewnode(data);//get address of newNode in root
}
else if(data<= root->data)
{
root->left=insert(root->left,data);
}
else
{
root->right=insert(root->right,data);
}
return root;
}
bool search(struct bstnode* root,int data) {
if(root == NULL) {
return false;
}
else if(root->data == data) {
return true;
}
else if(data <= root->data) {
return Search(root->left,data);
}
else
{
return Search(root->right,data);
}
}//getting error here.
将确切的错误复制到问题中。没有解释。 – StoryTeller
这是文件中的最后一个功能吗? – StoryTeller
是的,最后一个功能。错误说:“输入结束时的预期声明或声明”。 – harsher