[자료구조]이진트리 생성, 순회 문제 + 소스코드
- 최초 등록일
- 2021.07.31
- 최종 저작일
- 2020.05
- 6페이지/ MS 워드
- 가격 2,000원
소개글
"[자료구조]이진트리 생성, 순회 문제 + 소스코드"에 대한 내용입니다.
목차
없음
본문내용
#include <stdio.h>
#include <stdlib.h>
#define MALLOC(p, s)\
if (!((p)=malloc(s))) {\
fprintf(stderr, "Insufficient memory");\
exit(EXIT_FAILURE);\
}
typedef struct NODE* LINK;
typedef struct NODE {
char data;
LINK leftChild;
LINK rightChild;
}NODE;
void createCompBinTree();
void inorder(LINK);
void preorder(LINK);
void postorder(LINK);
LINK a, b, c, d, e;
int main()
{
printf("creating a binary tree\n");
createCompBinTree();
printf("\nthree binary tree traversals\n");
printf("inorder traversal : ");
inorder(a);
puts("");
printf("preorder traversal : ");
preorder(a);
puts("");
printf("postorder traversal : ");
postorder(a);
puts("");
return 0;
}
void createCompBinTree()
{
MALLOC(a, sizeof(NODE));
MALLOC(b, sizeof(NODE));
MALLOC(c, sizeof(NODE));
MALLOC(d, sizeof(NODE));
MALLOC(e, sizeof(NODE));
a->data = 'A';
b->data = 'B';
c->data = 'C';
d->data = 'D';
e->data = 'E';
참고 자료
없음