Cで二分探索木を実装しようとしています.. MinGWコンパイラでcodeblocks ideを使用しています
次のコードを実行しようとすると、このランタイム エラー プロセスは process return 0xC00000fd を返します
しかし、http://ideone.com/ でコンパイルすると、エラーなしで正常に動作します
解決済み : @user1161318 に感謝
#include <stdio.h>
#include <stdlib.h>
struct node
{
struct node *left;
struct node *right;
struct node *parent;
int value;
}*r;
void inorder(struct node *root)
{
int sam;
if(root)
{
inorder(root->left);
sam = root->value;
printf(" %d ->",sam);
inorder(root->right);
}
}
void insert(struct node *root,int x)
{
struct node *temp = (struct node*)malloc(sizeof(struct node));
temp->value = x;
struct node *y=root;
while(root)
{
y = root;
if(root->value > x)
{
root = root->left;
}
else
{
root = root->right;
}
}
temp->parent = y;
if(!y)
{
r=temp;
}
else if(x > y->value)
{
y->right = temp;
}
else
{
y->left = temp;
}
}
int main()
{
int i;
for(i=0; i<10; i++)
{
insert(r,i);
}
inorder(r);
return 0;
}