이진탐색트리 기초문제입니다 오류좀 봐주세요ㅠㅠ젭알젭알 급해요ㅠㅠ
두메꽃
질문 제목 : 이진탐색트리 기초문제입니다 오류좀 봐주세요ㅠㅠ젭알젭알 급해요ㅠㅠ이진탐색트리 삽입 후 제일큰노드 작은노드 출력하기질문 내용 :
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 함수가 출력이 안되네요ㅠ
최적 코드가 아니라 그냥 출력값만 나오게 하면 되는건데ㅠ 어렵네용ㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |