BST 프로그램을 구현하려고 시도했지만 런타임 오류로 인해 실행이 실패했습니다. 그것을 수정하는 방법을 알려주십시오. 트리의 생성을위한 내 코드는 다음과 같습니다BST null 포인터 할당 오류
struct node *createBinTree()
{ int val,size;
struct node *bintree, *newnode;
bintree= NULL;
printf("Enter the values of nodes terminated by a negetive no.\n");
val=0;
while(val>=0)
{
printf("\nEnter value");
scanf("%d",&val);
if(val>=0)
{ newnode = (struct node*)sizeof(struct node);
newnode->val=val;
newnode->lchild= NULL;
newnode->rchild= NULL;
bintree=attach(bintree,newnode);
}
}
return bintree;
}
struct node *attach(struct node *tree,struct node* tnode)
{if(tree==NULL)
tree=tnode;
else{
if(tnode->val<tree->val)
tree->lchild= attach(tree->lchild,tnode);
else
tree->rchild= attach(tree->rchild,tnode);
}
return tree;
}
당신이 무엇을 기대합니까? 'newnode = (struct node *) sizeof (struct node); ' – acraig5075
아직 디버거를 사용하지 않았다면 지금은 완벽한 시간입니다. 디버거에서 프로그램을 실행하면 충돌 위치를 찾는 데 도움이 될뿐만 아니라 호출 스택을보고 해당 위치에서 어떻게 끝났는지 알 수 있으며 변수가 무엇인지 알아낼 수 있습니다. 충돌. –
무엇이 오류인지 알려주세요. 게시물 끝에있는 "편집"링크를 사용하여이 정보를 추가하십시오. – ForceMagic