#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct treeNode
{
char *name;
char *tel;
char *mail;
struct treeNode *left;
struct treeNode *right;
}treeNode;
treeNode* insertNode(treeNode *p,char *name,char *tel,char *mail)
{
p = (treeNode*)malloc(sizeof(treeNode));
if(p == NULL) /// 이 부분이 문제!!
{
strcpy(p->name,name);
strcpy(p->tel,tel);
strcpy(p->mail,mail);
return p;
}
else if(p->left == NULL)
p->left = insertNode(p->left,name,tel,mail);
else if(p->right == NULL)
p->right = insertNode(p->right,name,tel,mail);
return p;
}
void displayInorder(treeNode* root)
{
if(root)
{
displayInorder(root->left);
printf(\"%s \",root->name);
printf(\"%s \",root->tel);
printf(\"%s \",root->mail);
displayInorder(root->right);
}
return;
}
int main()
{
treeNode *root;
root = NULL;
insertNode(root,\"룰루\",\"0101234\",\"forhswkd\");
displayInorder(root);
getchar();
return 0;
}
c언어로 자료구조 공부중인데요.
트리를 써서 주소록을 만드는 것을 하는 중인데,
insertNode에서 if(p == NULL) 를 들어가지 않는데,
조건문이 잘못된건가요?
이것저것 해봤는데 해결이 안되서 도움청해봅니다 ㅠㅠ..
이건 뭔 개근가..p에 동적할당했는데 p==NULL이면 당연히 안들어가겠지 p!=NULL이겠지...
아 그렇군요!!! 감사합니다!!!
시비걸거면 말을하지마셍 시2발련2 나가뒤지3