이진탐색트리 기초문제입니다 오류좀 봐주세요ㅠㅠ젭알젭알 급해요ㅠㅠ
두메꽃
질문 제목 : 이진탐색트리 기초문제입니다 오류좀 봐주세요ㅠㅠ젭알젭알 급해요ㅠㅠ이진탐색트리 삽입 후 제일큰노드 작은노드 출력하기질문 내용 :
1) 문자가 아닌 정수를 삽입.
2) 삽입기능 함수(탐색, 삭제 기능 필요 없지만, searchbst 함수 이용해도 좋음)
3) 어떤 노드가 주어지면, 이 노드의 좌측 서브트리에서 key값이 가장 큰 노드를 반환하는 maxnode 함수와우측 서브트리에서 key값이 가장 작은 노드를 반환하는 minnode 함수
4) main 에서 아래와 같은 트리를 만듦.
5) “기준 노드를 입력하세요” 출력하고, 값을 입력 받음.
6) “기준노드의 좌측서브트리에서 가장 큰 노드는 o, 우측서브트리에서 가장 작은 노드는 o 입니다” 출력 8
3 10
2 5 14
4 11 16
이게 문제구요
#includestdio.h
#includestdlib.h
typedef struct listnode
{
int key;
struct listnode* r;
struct listnode* l;
}listnode;
typedef struct{
listnode * head;
}linkedlist_h;
linkedlist_h * createlinkedlist_h(void);
void insertbst(linkedlist_h* l,int x);
int maxnode(linkedlist_h* l);
int minnode(linkedlist_h* l);
linkedlist_h * createlinkedlist_h(void)
{
linkedlist_h * l;
l = (linkedlist_h*)malloc(sizeof(linkedlist_h));
l - head = null;
return l;
}
void insertbst(linkedlist_h* l,int x)
{
listnode *p;
listnode *q;
listnode *bst;
bst = l - head;
p=bst;
listnode* newnode;
newnode = (listnode*)malloc(sizeof(listnode));
newnode-key = x;
newnode-l=null;
newnode-r=null;
while (p!=null)
{
if(x==p-key) return;
q=p;
if(xp-key)
{
p=p-l;
}
else
{
p=p-r;
}
}
if(bst==null)
{
bst = newnode;
return;
}
else if(xq-key)
{
q-l=newnode;
}
else
{
q-r=newnode;
}
return;
}
int maxnode(linkedlist_h* l)
{
int a=0;
listnode *p;
p=l-head;
p=p-l;
if(p-r!=null)
{
p=p-r;
}
else
{
a=p-key;
}
return a;
}
int minnode(linkedlist_h* l)
{
int a=0;
listnode *p;
p=l-head;
p=p-r;
if(p-l!=null)
{
p=p-l;
}
else
{
a=p-key;
}
return a;
}
void main()
{
linkedlist_h * l;
l = createlinkedlist_h();
int x[20],a, i,n,m;
printf(삽입하고 싶은 노드의 수를 입력하시오);
scanf(%d,&a);
for(i=1; i=a; i++)
{
printf(기준 노드를 입력하세요);
scanf(%d,&x[i]);
insertbst(l,x[i]);
}
n=minnode(l);
m=maxnode(l);
printf(기준노드의 좌측서브트리에서 가장 큰 노드는 %d, 우측서브트리에서 가장 작은 노드는 %d 입니다,m,n);
}
이게 제가짠 코드입니다ㅠ
출력값이 아무것도 안오고 에러랑 워닝도 0이라서 문제점도모르겠어요ㅠ
min max 함수가 출력이 안되네요ㅠ
최적 코드가 아니라 그냥 출력값만 나오게 하면 되는건데ㅠ 어렵네용ㅠ