Menu
Coddy logo textTech

Pre-order Traversal

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

challenge icon

챌린지

쉬움

전위 순회(Pre-order traversal):

  1. 루트 노드를 방문합니다.
  2. 왼쪽 서브트리를 순회합니다.
  3. 오른쪽 서브트리를 순회합니다.

BinaryTree에 전위 순회 방식으로 값을 출력하고, 각 값 뒤에 공백을 추가하는 preOrderPrint 메서드를 추가하세요.

직접 해보기

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

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);
    BinaryTree_preOrderPrint(&bt);
    return 0;
}

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