c언어 및 자료구조 오류 좀...
딥블루
문제가
1. 이진탐색트리를 이용하여 오름차순 결과 출력
2. 이진탐색트리를 이용하여 내림차순 결과 출력
3. 히프트리를 이용하여 오름차순 결과 출력
어디가 틀렸는지.... 오류 수정좀....
#includestdio.h
typedef struct Tree node
{
int key;
struct tree node *left,*right;
}
Tree node;
typedef struct
{
int key;
}
element;
typedef struct
{
element *heap;
int heap_size;
}
Heap Type; //Tree
void insert_Node(treeNode **root, int key)
{
Tree Node *parent,*cur;
Tree Node *new_node;
cur=*root;
parnet=NULL;
while ( cur != NULL)
{
if(key==cur-key)
return;//이미존재
parent=cur;
if(keycur-key)
cur=cur-left;
else cur=cur-right;
}
new_node=(TreeNode*)malloc(sizeof(TreeNode);
if(new_node==NULL)
return;//데이터 복사
new_node-key=key;
new_node-left=new_node-right=NULL;
if(parent!=NULL)
if(keyparent-key)
parent-left=new_node;
else parent -right=new_node;
else*root=new_node;
void
*Binary_Tree_Accend(Tree Node *node)
{
if(node!=NULL)
{
Binary_Tree_Accend (node-left);
printf(%d,node-key);
Binary_Tree_Accend(node-right);
}
void Binary_Tree_Deccend(node-right);
printf(%d,node-key);
Binary_Tree_Deccend(node-left);}
}//Heap
void init(HeapType*h,int num)
{
h-heap=(element *) malloc(sizeof(element)*num);
h-heap-size=0;
}
void insert_max-heap(Heap Type*h,element item)
{
int i;
i=++(h-heap_size);
while((i!=1)&&(item.key-h-heap[i/2]].key))
{
h-heap[i]=h-heap[i/2];
]
i/=2;
}
h-heap[i]=item;
}
int delete_max_heap(Heap Type *h)
{
int parent,child,t;
element item,temp;
item=h-heap[1];
temp=h-heap[(h-heap-size)--];
parine=1;
child=2;
while (child = h - heap-size)
{
if((child h -heap_size)&&(h-heap[child]key)
h-heap[child+1]key) child ++;
if(temp.key=h-heap[child].key)break;
h-heap[parent]=h-heap[child];
parent=child;
child*2;
}
h- heap[parent]=temp;
t=item.key;
returnt;
}
void Heap_Tree_Accend (Heap Type *heap,intn)
{
int i;
for(i=(n-1); i=0;, i--)
{
printf(%d, delete_max-heap(heap));
}
}
int main()
{
input,n,i;
int *heap_arry=NULL;
int *node =NULL;
TreeNode*root=NULL;
}
HeapType heap;
element ele;
printf(입력할 노드 개수: );
scanf(%d, &input);
init(&heap,input);
heap_array=(int *)
malloc((sizeof(heap_array)*input);
printf(노드를 %d개 만큼 입력해주세요\ninput);
for(i=0; i=0; i--)
{
heap_array[i]=dellete_max_heap(&heap);}어느것이 문제입니까??
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
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 |