Menu
Coddy logo textTech

Build Tree

Coddy의 이진 트리 - 자료구조 시리즈 #3 코스 레슨 — 13개 중 6번째.

challenge icon

챌린지

쉬움

BinaryTree에 트리의 재귀적 문자열 표현(비어 있는 경우 null을 포함하는 [value, leftSubtree, rightSubtree] 형식)을 받아 트리를 생성하는 buildTree 메서드를 추가하세요.

직접 해보기

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "binarytree.h"

void rtl(Node* n) {
    if (n == NULL) return;
    printf("%d\n", Node_getValue(n));
    rtl(Node_getRight(n));
    rtl(Node_getLeft(n));
}

int main() {
    char buf[4096];
    if (!fgets(buf, sizeof(buf), stdin)) buf[0] = '\0';
    buf[strcspn(buf, "\r\n")] = '\0';
    BinaryTree bt;
    BinaryTree_init(&bt);
    BinaryTree_buildTree(&bt, buf);
    rtl(BinaryTree_getRoot(&bt));
    return 0;
}

이진 트리 - 자료구조 시리즈 #3의 모든 레슨