mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-03 19:52:01 +08:00
Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
package chapter_tree
|
||||
|
||||
/* 配列表現による二分木クラス */
|
||||
/* 配列で表した二分木クラス */
|
||||
type arrayBinaryTree struct {
|
||||
tree []any
|
||||
}
|
||||
@@ -16,31 +16,31 @@ func newArrayBinaryTree(arr []any) *arrayBinaryTree {
|
||||
}
|
||||
}
|
||||
|
||||
/* リスト容量 */
|
||||
/* リストの容量 */
|
||||
func (abt *arrayBinaryTree) size() int {
|
||||
return len(abt.tree)
|
||||
}
|
||||
|
||||
/* インデックス i のノードの値を取得 */
|
||||
/* インデックス i のノードの値を取得する */
|
||||
func (abt *arrayBinaryTree) val(i int) any {
|
||||
// インデックスが範囲外なら、空きを表す null を返す
|
||||
// インデックスが範囲外の場合、空きを表す null を返す
|
||||
if i < 0 || i >= abt.size() {
|
||||
return nil
|
||||
}
|
||||
return abt.tree[i]
|
||||
}
|
||||
|
||||
/* インデックス i のノードの左子ノードのインデックスを取得 */
|
||||
/* インデックス i のノードの左の子ノードのインデックスを取得する */
|
||||
func (abt *arrayBinaryTree) left(i int) int {
|
||||
return 2*i + 1
|
||||
}
|
||||
|
||||
/* インデックス i のノードの右子ノードのインデックスを取得 */
|
||||
/* インデックス i のノードの右の子ノードのインデックスを取得する */
|
||||
func (abt *arrayBinaryTree) right(i int) int {
|
||||
return 2*i + 2
|
||||
}
|
||||
|
||||
/* インデックス i のノードの親ノードのインデックスを取得 */
|
||||
/* インデックス i のノードの親ノードのインデックスを取得する */
|
||||
func (abt *arrayBinaryTree) parent(i int) int {
|
||||
return (i - 1) / 2
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (abt *arrayBinaryTree) parent(i int) int {
|
||||
/* レベル順走査 */
|
||||
func (abt *arrayBinaryTree) levelOrder() []any {
|
||||
var res []any
|
||||
// 配列を直接走査する
|
||||
// 配列をそのまま走査する
|
||||
for i := 0; i < abt.size(); i++ {
|
||||
if abt.val(i) != nil {
|
||||
res = append(res, abt.val(i))
|
||||
@@ -57,43 +57,43 @@ func (abt *arrayBinaryTree) levelOrder() []any {
|
||||
return res
|
||||
}
|
||||
|
||||
/* 深さ優先探索 */
|
||||
/* 深さ優先走査 */
|
||||
func (abt *arrayBinaryTree) dfs(i int, order string, res *[]any) {
|
||||
// 空きスロットなら返す
|
||||
// 空きの場合、戻る
|
||||
if abt.val(i) == nil {
|
||||
return
|
||||
}
|
||||
// 先行順走査
|
||||
// 行きがけ順走査
|
||||
if order == "pre" {
|
||||
*res = append(*res, abt.val(i))
|
||||
}
|
||||
abt.dfs(abt.left(i), order, res)
|
||||
// 中順走査
|
||||
// 通りがけ順走査
|
||||
if order == "in" {
|
||||
*res = append(*res, abt.val(i))
|
||||
}
|
||||
abt.dfs(abt.right(i), order, res)
|
||||
// 後順走査
|
||||
// 帰りがけ順走査
|
||||
if order == "post" {
|
||||
*res = append(*res, abt.val(i))
|
||||
}
|
||||
}
|
||||
|
||||
/* 先行順走査 */
|
||||
/* 行きがけ順走査 */
|
||||
func (abt *arrayBinaryTree) preOrder() []any {
|
||||
var res []any
|
||||
abt.dfs(0, "pre", &res)
|
||||
return res
|
||||
}
|
||||
|
||||
/* 中順走査 */
|
||||
/* 通りがけ順走査 */
|
||||
func (abt *arrayBinaryTree) inOrder() []any {
|
||||
var res []any
|
||||
abt.dfs(0, "in", &res)
|
||||
return res
|
||||
}
|
||||
|
||||
/* 後順走査 */
|
||||
/* 帰りがけ順走査 */
|
||||
func (abt *arrayBinaryTree) postOrder() []any {
|
||||
var res []any
|
||||
abt.dfs(0, "post", &res)
|
||||
|
||||
Reference in New Issue
Block a user