Files
Yudong Jin 2f561d3d51 feat(ko): add the Korean online edition (#2006)
* feat(ko): add the complete Korean online edition

* Use UTF-8 for Python CI output on Windows

* Remove print-book promotion from the Korean site

* fix(ko): preserve emphasis before Korean particles
2026-10-29 03:46:43 +08:00

45 lines
923 B
Go

// File: binary_tree_dfs.go
// Created Time: 2022-11-26
// Author: Reanon ([email protected])
package chapter_tree
import (
. "github.com/krahets/hello-algo/pkg"
)
var nums []any
/* 전위 순회 */
func preOrder(node *TreeNode) {
if node == nil {
return
}
// 방문 우선순위: 루트 노드 -> 왼쪽 서브트리 -> 오른쪽 서브트리
nums = append(nums, node.Val)
preOrder(node.Left)
preOrder(node.Right)
}
/* 중위 순회 */
func inOrder(node *TreeNode) {
if node == nil {
return
}
// 방문 우선순위: 왼쪽 서브트리 -> 루트 노드 -> 오른쪽 서브트리
inOrder(node.Left)
nums = append(nums, node.Val)
inOrder(node.Right)
}
/* 후위 순회 */
func postOrder(node *TreeNode) {
if node == nil {
return
}
// 방문 우선순위: 왼쪽 서브트리 -> 오른쪽 서브트리 -> 루트 노드
postOrder(node.Left)
postOrder(node.Right)
nums = append(nums, node.Val)
}