수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • 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을 누르면 다음 라인을 진행하구

    하단의 변수 값들도 변하

번호 제 목 글쓴이 날짜
2700562 함수포인터에서요 (7) 소심한여자 2025-07-06
2700530 전처리문 질문입니다. (1) 아놀드 2025-07-05
2700510 c언어를 어케하면 잘할수 있을까요.. 연연두 2025-07-05
2700484 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) 날위해 2025-07-05
2700426 인터넷 창 띄우는 질문이요 (1) 정훈 2025-07-04
2700400 원넓이를 계산이요 ㅜㅜ 천칭자리 2025-07-04
2700368 if에 관해서 질문이요... Orange 2025-07-04
2700339 이거 결과값이 왜이런건지.. (4) 그댸와나 2025-07-04
2700313 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) 크나 2025-07-03
2700287 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) 아련나래 2025-07-03
2700264 문자와 숫자 동시에 입력??? 글고운 2025-07-03
2700236 txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) 미국녀 2025-07-03
2700211 전위 연산자 (2) 어른처럼 2025-07-02
2700183 C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; 피스케스 2025-07-02
2700150 꼭좀 도와주세요ㅠㅠㅠ 호습다 2025-07-02
2700095 연산문제...질문... 오빤테앵겨 2025-07-01
2700070 while문 , 3의배수 출력하는 프로그램좀 짜주세욤. 횃불 2025-07-01
2700041 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? 헛장사 2025-07-01
2700012 배열// (1) 전갈자리 2025-07-01
2699895 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) 선아 2025-06-30
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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