-1
当我尝试使用C中的结构创建二叉树时,出现总线错误。请给我一个解决方案来克服这种总线错误。我在Mac OSX上编译。当在C中创建二叉树时在Mac上发生总线错误10
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node* left;
struct node* right;
};
struct node* NewNode(int data) {
struct node* inode ;
inode->data = data;
inode->left = NULL;
inode->right = NULL;
printf("%d\n", inode->data);
return(inode);
}
struct node* insert(struct node* node ,int data){
if(node == NULL)
return(NewNode(data));
else{
if(data <= node->data)
node->left = insert(node->left, data);
else
node->right = insert(node->right, data);
return(node);
}
}
struct node* build123a() {
struct node* root = newNode(2);
struct node* lChild = newNode(1);
struct node* rChild = newNode(3);
root->left = lChild;
root->right= rChild;
return(root);
}
int main(void) {
build123a();
}
输出继电器:10
三江源...我的问题解决了 – srikayala 2013-04-19 07:07:11