트리 순회코드인데요 오류의 원인이 뭘까요??
한결
#include stdio.h
#include malloc.h
struct tnode
{
int data;
struct tnode *left_child;
struct tnode *right_child;
};
typedef struct tnode node;
typedef node *tree_ptr;
tree_ptr temp insert(tree_ptr head, int number)
{
tree_ptr temp=NULL;
tree_ptr insertpoint = NULL;
if(!head)
{
temp=(tree_ptr)malloc(sizeof(node));
temp-data=number;
temp-left_child=temp-right_child=NULL;
return temp;
}
insertpoint = head;
for(;;)
{
if((insertpoint-datanumber)&&(insertpoint-left_child!=NULL))
insertpoint = insertpoint-left_child;
else if(insertpoint-data==number)
return head;
else if((insertpoint-datanumber)&&(insertpoint-right_child!=NULL))
insertpoint = insertpoint-right_child;
else break;
}
temp=(tree_ptr)malloc(sizeof(node));
temp-data=number;
temp-left_child=temp-right_child=NULL;
if(insertpoint-datanuber)
insertpoint-right_child=temp;
else
insertpoint-left_child=temp;
return head;
}
void inorder(tree_ptr ptr)
{
if(ptr)
{
inorder(ptr-left_child);
printf(%d,ptr-data);
inorder(ptr-right_child);
}
}
void postorder(tree_ptr ptr)
{
if(ptr)
{
postorder(ptr-left_child);
postorder(ptr-right_child);
printf(%d,ptr-data);
}
}
void preorder(tree_ptr ptr)
{
if(ptr)
{
printf{%d,ptr-data);
preorder(ptr-left_child);
preorder(ptr-right_child);
}
}
int main()
{
int i;
int arr[100];
tree_ptr head=NULL;
for(i=0;i100;i++)
{
scanf{%d,&arr[i]};
head=insert(head,number[i]);
if(arr[i]=-1)
break;
}
printf(inorder:);
inorder(head);
printf(\n);
printf(postorder:);
postorder(head);
printf(\n);
printf(preorder:);
preorder(head);
printf(\n);
}
-
송아리
printf{\%d\
-
사라
비주얼스튜디오로 작성하는경우
디버깅하는방법만알면 충분히 할수있어요
프로그래을 ctrl+f5는 이제부터 누르지마시고
디버깅을 해보세요.
먼저 자신이 자신있게 잘짯다고 생각하거나,
이부분이 의심스러운곳에서
f9 눌러요. 빨간점이 왼쪽에 생기구요
이제 f5(디버깅시작이며 빨간점에서 멈춤)
누르면 아까 점찍은데서 멈출거에요
이때 화면하단쯤에 자동,지역,조사식 등이 나올거에요
f10을 누르면 다음 라인을 진행하구
하단의 변수 값들도 변하
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |
2695010 | C++의 STL은 왜 굳이 템플릿화 시켜서 라이브러리를 만드나요? (초보수준의 질문..) (2) | 엘보어 | 2025-05-16 |
2694958 | 로직이 변한다는 것에 대해서 궁금합니다. | 튼동 | 2025-05-16 |
2694929 | 열혈강의 25-2 두번째 문제 질문 | 지우개 | 2025-05-15 |
2694900 | dequeue 에서 리턴값 프린트 방법알려주세요 오늘 12시까지 대화방에 있습니다 도와주세요 | 미투리 | 2025-05-15 |
2694854 | 절대값을 구할때 (2) | 그녀는귀여웠다 | 2025-05-15 |
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |