NULL 대신 nil -1 사용하는 이유가 int에서 NULL쓰면 0되서 구조체배열[0]번째랑 겹치니까 -1로 써주는건가요?



#define MAX_SIZE 100

struct tnode {

int left;

char name[20];

int right;

};

#define nil -1


main()

{

struct tnode a[MAX_SIZE] = {

{1,"김이연",2},

{ nil,"김김김",4},

{3,"나문희",nil },

{ nil,"나나나",nil },

{ nil,"김나나",nil }

};

int p;

char key[20];

printf("search_name->");

scanf("%s", key);

p = 0;

while (1)

{

if (p == nil)

{

printf("못찾음"); break;

}

if (strcmp(key, a[p].name) == 0)

{

printf("찾음 \n"); break;

}

else if (strcmp(key, a[p].name) < 0) 

p = a[p].left;


else

p = a[p].right;

}

}