여기 해결방법좀 알려주세요 ㅠ
동생몬
질문 제목 : 이진트리 높이구하는거요..높이 구현햇는데 자꾸에러가 되요 ㅠ질문 내용 :
#includestdio.h
#includestdlib.h
typedef struct _node {
int key;
struct _node *left;
struct _node *right;
} node;
node *head, *tail;
int left,right;
void init_tree(void)
{
head = (node*)malloc(sizeof(node));
tail = (node*)malloc(sizeof(node));
head-left = tail;
head-right = tail;
tail-left = tail;
tail-right = tail;
}
node * insert_node(node *t, int tag, int key)
{
node *c = (node *) malloc(sizeof(node));
c-key = key;
c-left = tail;
c-right = tail;
if(tag == left)
{
t-left = c;
}
else t-right = c;
return c;
}
int max(int a, int b)
{
if(ab)
return a;
else
return b;
}
int height(node *t)
{
int a=0,b=0;
if(t!=null)
{
a= 1+height(t-left);
b= 1+height(t-right);
return max(a,b);
}
return 0;
}
void main()
{
int r;
node *child;
init_tree();
child=insert_node(head, left, 1);
child=insert_node(head-left,left, 2);
child=insert_node(head-left,right,3);
child=insert_node(child,left, 4);
child=insert_node(child,right,5);
r= height(head-left);
printf(height: %d\n, r);
}
빨간줄 친 저부분이 자꾸 에러가 되요 ㅠ
어떻게 수정해야하나요 조금만 도움 주세요 ㅠ
-
옆집오빠야 2024-01-03
네 감사합니다 혹시 팁같은건 없을가요 ㅎㅎ
다시 해볼게요 ㅎㅎ -
청력 2024-01-03
에러가 나오지 않는다고 해서
저 프로그램이 정확한 결과를 나오게 하는것은 직접 작성하신 작성자께서 푸셔야 할 문제 입니다. -
베네딕트 2024-01-03
max이름을 사용못하는건가요? 다른이름해도 작동이안되던데..설명좀 부탁드려요 ㅠ
-
패틱 2024-01-03
max 라는 함수를 다른 이름으로 바꾸시면 됩니다.
그렇게 하면 에러 화면은 나오지 않습니다. -
레온 2024-01-03
그러면 max함수를 사용하지 말아야하는건가요?
-
보르미 2024-01-03
c 라이브러리에 max 라는 함수가 있기 때문에 에러 입니다.