수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

트리 순회코드인데요 오류의 원인이 뭘까요??

한결

2023.04.01

#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);
}

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

  • 송아리

    printf{\%d\

  • 사라

    비주얼스튜디오로 작성하는경우

    디버깅하는방법만알면 충분히 할수있어요

    프로그래을 ctrl+f5는 이제부터 누르지마시고

    디버깅을 해보세요.


    먼저 자신이 자신있게 잘짯다고 생각하거나,
    이부분이 의심스러운곳에서

    f9 눌러요. 빨간점이 왼쪽에 생기구요

    이제 f5(디버깅시작이며 빨간점에서 멈춤)
    누르면 아까 점찍은데서 멈출거에요

    이때 화면하단쯤에 자동,지역,조사식 등이 나올거에요

    f10을 누르면 다음 라인을 진행하구

    하단의 변수 값들도 변하

번호 제 목 글쓴이 날짜
2694420 C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) 은새 2025-05-11
2694370 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 들찬 2025-05-10
2694339 putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) 미르 2025-05-10
2694316 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) 나빛 2025-05-10
2694285 언어 공부하는 과정 좀 추천해주세요! (1) 아빠몬 2025-05-09
2694258 카운터.. 질문입니다. (4) 하늘빛눈망울 2025-05-09
2694229 단순한 질문이요 (8) 여름 2025-05-09
2694202 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) 미나 2025-05-09
2694145 화면깜빡임을 없애고 싶은데요... (1) 어서와 2025-05-08
2694069 unsigned 질문입니다. 힘차 2025-05-07
2694012 전공 비전공자 개발자 (10) 말글 2025-05-07
2693984 오버로딩이 무엇인가요? (2) 헛매질 2025-05-07
2693956 PlaySound재생이 안됩니다!(C에 음악넣기) 지존 2025-05-06
2693928 &와 *의 사용에 관한 명확한 이해 제나 2025-05-06
2693903 반복문 설명좀요 ㅠㅠ (2) 란새 2025-05-06
2693869 stdio.h 는 왜 쓰는건가요? (1) 큰꽃들 2025-05-06
2693842 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) 진솔 2025-05-05
2693811 소수 출력;;;; 화이트캣 2025-05-05
2693788 이런 함수는 없나요? (3) 앤드류 2025-05-05
2693758 txt파일 불러와서 행렬로 저장 큰애 2025-05-05
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com