회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
[c] 1991 트리 순회 질문
1991번 - 트리 순회
gumdung
6년 전
0
뭐가 잘못된건지 잘 안보입니다....도와주시면감사하겠습니다.
#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct node{ char data; struct node *left,*right; }Node; void Fprint(Node *tmp); void Cprint(Node *tmp); void Lprint(Node *tmp); void Clear(); Node *Insert(Node *tmp,char t,char l,char r); Node *Search(Node *tmp,char t,char l,char r); Node *makenode(); int main() { int n; char t,l,r; Node *root=NULL; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%c",&t); Clear(); scanf("%c",&l); Clear(); scanf("%c",&r); root=Insert(root,t,l,r); } Fprint(root); printf("\n"); Cprint(root); printf("\n"); Lprint(root); return 0; } void Clear() { while(getchar()!='\n'); } void Fprint(Node *tmp) { if(tmp==NULL)return; printf("%c",tmp->data); Fprint(tmp->left); Fprint(tmp->right); } void Cprint(Node *tmp) { if(tmp==NULL)return; Fprint(tmp->left); printf("%c",tmp->data); Fprint(tmp->right); } void Lprint(Node *tmp) { if(tmp==NULL)return; Fprint(tmp->left); Fprint(tmp->right); printf("%c",tmp->data); } Node *Insert(Node *tmp,char t,char l,char r) { if(tmp==NULL) { tmp=makenode(); tmp->data=t; if(l!='.') { tmp->left=makenode(); tmp->left->data=l; } if(r!='.') { tmp->right=makenode(); tmp->right->data=r; } return tmp; } else { tmp=Search(tmp,t,l,r); return tmp; } } Node *Search(Node *tmp,char t,char l,char r) { if(tmp->data==t) { if(l != '.'){ tmp->left=makenode(); tmp->left->data=l; } if(r != '.'){ tmp->right=makenode(); tmp->right->data=r; } return tmp; } else { Search(tmp->left,t,l,r); Search(tmp->right,t,l,r); } } Node *makenode() { Node *newnode=(Node*)malloc(sizeof(Node)); newnode->left=NULL; newnode->right=NULL; return newnode; }
댓글을 작성하려면
로그인
해야 합니다.
gumdung 6년 전
뭐가 잘못된건지 잘 안보입니다....도와주시면감사하겠습니다.