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:
Yudong Jin
2026-10-30 02:12:26 +08:00
committed by GitHub
parent 455e8c1281
commit 7257641e0e
1987 changed files with 23531 additions and 23261 deletions

View File

@@ -14,54 +14,54 @@ import heapq
def test_push(heap: list, val: int, flag: int = 1):
heapq.heappush(heap, flag * val) # 要素をヒープに追加
print(f"\n要素 {val} をヒープに追加した後")
heapq.heappush(heap, flag * val) # ヒープに要素を挿入する
print(f"\n要素 {val} をヒープに挿入した後")
print_heap([flag * val for val in heap])
def test_pop(heap: list, flag: int = 1):
val = flag * heapq.heappop(heap) # ヒープ頂点の要素を取り出す
print(f"\nヒープ先頭要素 {val} を取り出した後")
val = flag * heapq.heappop(heap) # ヒープの先頭要素を取り出す
print(f"\nヒープの先頭要素 {val} を取り出した後")
print_heap([flag * val for val in heap])
"""Driver Code"""
"""実行用コード"""
if __name__ == "__main__":
# 最小ヒープを初期化
# 最小ヒープを初期化する
min_heap, flag = [], 1
# 最大ヒープを初期化
# 最大ヒープを初期化する
max_heap, flag = [], -1
print("\n以下のテストケースは最大ヒープ")
# Python の heapq モジュールはデフォルトで最小ヒープを実装している
# 要素を負にしてからヒープに入れると大小関係を反転でき、最大ヒープを実現できる
# この例では、flag = 1 が最小ヒープ、flag = -1 が最大ヒープに対応する
print("\n以下のテストケースは最大ヒープを対象とする")
# Python の heapq モジュールは既定で最小ヒープを実装する
# 「要素の符号を反転」してからヒープに挿入すれば、大小関係が逆転し、最大ヒープを実装できる
# この例では flag = 1 が最小ヒープ、flag = -1 が最大ヒープに対応する
# 要素をヒープに追加
# ヒープに要素を挿入する
test_push(max_heap, 1, flag)
test_push(max_heap, 3, flag)
test_push(max_heap, 2, flag)
test_push(max_heap, 5, flag)
test_push(max_heap, 4, flag)
# ヒープ頂点の要素を取得
# ヒープの先頭要素を取得する
peek: int = flag * max_heap[0]
print(f"\nヒープ先頭要素は {peek}")
print(f"\nヒープの先頭要素は {peek}")
# ヒープ頂点の要素を取り出す
# ヒープの先頭要素を取り出す
test_pop(max_heap, flag)
test_pop(max_heap, flag)
test_pop(max_heap, flag)
test_pop(max_heap, flag)
test_pop(max_heap, flag)
# ヒープのサイズを取得
# ヒープのサイズを取得する
size: int = len(max_heap)
print(f"\nヒープ要素数は {size}")
print(f"\nヒープの要素数は {size}")
# ヒープが空かどうかを判定
# ヒープが空か判定
is_empty: bool = not max_heap
print(f"\nヒープが空かどうかは {is_empty}")
print(f"\nヒープは空か {is_empty}")
# リストを入力してヒープを構築する
# 時間計算量は O(n) であり、O(nlogn) ではない