我不會錯過任何}或;那麼爲什麼我得到這個錯誤? 實際錯誤顯示「輸入結束時的預期聲明或聲明」。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