mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-04 12:12:45 +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:
@@ -6,17 +6,17 @@
|
||||
|
||||
namespace hello_algo.chapter_hashing;
|
||||
|
||||
/* キーと値の組 int->string */
|
||||
/* キーと値のペア int->string */
|
||||
class Pair(int key, string val) {
|
||||
public int key = key;
|
||||
public string val = val;
|
||||
}
|
||||
|
||||
/* 配列ベースのハッシュテーブル */
|
||||
/* 配列で実装したハッシュテーブル */
|
||||
class ArrayHashMap {
|
||||
List<Pair?> buckets;
|
||||
public ArrayHashMap() {
|
||||
// 100 個のバケットを含む配列を初期化
|
||||
// 100 個のバケットを含む配列を初期化する
|
||||
buckets = [];
|
||||
for (int i = 0; i < 100; i++) {
|
||||
buckets.Add(null);
|
||||
@@ -29,7 +29,7 @@ class ArrayHashMap {
|
||||
return index;
|
||||
}
|
||||
|
||||
/* 検索操作 */
|
||||
/* 取得操作 */
|
||||
public string? Get(int key) {
|
||||
int index = HashFunc(key);
|
||||
Pair? pair = buckets[index];
|
||||
@@ -47,11 +47,11 @@ class ArrayHashMap {
|
||||
/* 削除操作 */
|
||||
public void Remove(int key) {
|
||||
int index = HashFunc(key);
|
||||
// null に設定し、削除を表す
|
||||
// null に設定して、削除を表す
|
||||
buckets[index] = null;
|
||||
}
|
||||
|
||||
/* すべてのキーと値のペアを取得 */
|
||||
/* キーと値のペアをすべて取得する */
|
||||
public List<Pair> PairSet() {
|
||||
List<Pair> pairSet = [];
|
||||
foreach (Pair? pair in buckets) {
|
||||
@@ -61,7 +61,7 @@ class ArrayHashMap {
|
||||
return pairSet;
|
||||
}
|
||||
|
||||
/* すべてのキーを取得 */
|
||||
/* すべてのキーを取得する */
|
||||
public List<int> KeySet() {
|
||||
List<int> keySet = [];
|
||||
foreach (Pair? pair in buckets) {
|
||||
@@ -71,7 +71,7 @@ class ArrayHashMap {
|
||||
return keySet;
|
||||
}
|
||||
|
||||
/* すべての値を取得 */
|
||||
/* すべての値を取得する */
|
||||
public List<string> ValueSet() {
|
||||
List<string> valueSet = [];
|
||||
foreach (Pair? pair in buckets) {
|
||||
@@ -81,7 +81,7 @@ class ArrayHashMap {
|
||||
return valueSet;
|
||||
}
|
||||
|
||||
/* ハッシュテーブルを出力 */
|
||||
/* ハッシュテーブルを表示する */
|
||||
public void Print() {
|
||||
foreach (Pair kv in PairSet()) {
|
||||
Console.WriteLine(kv.key + " -> " + kv.val);
|
||||
@@ -93,40 +93,40 @@ class ArrayHashMap {
|
||||
public class array_hash_map {
|
||||
[Test]
|
||||
public void Test() {
|
||||
/* ハッシュテーブルを初期化 */
|
||||
/* ハッシュテーブルを初期化する */
|
||||
ArrayHashMap map = new();
|
||||
|
||||
/* 追加操作 */
|
||||
// ハッシュテーブルにキーと値のペア (key, value) を追加
|
||||
map.Put(12836, "シャオハー");
|
||||
map.Put(15937, "シャオルオ");
|
||||
map.Put(16750, "シャオスワン");
|
||||
map.Put(13276, "シャオファー");
|
||||
map.Put(10583, "シャオヤー");
|
||||
Console.WriteLine("\n追加完了後、ハッシュテーブルは\nKey -> Value");
|
||||
// ハッシュテーブルにキーと値のペア (key, value) を追加する
|
||||
map.Put(12836, "小哈");
|
||||
map.Put(15937, "小啰");
|
||||
map.Put(16750, "小算");
|
||||
map.Put(13276, "小法");
|
||||
map.Put(10583, "小鸭");
|
||||
Console.WriteLine("\n追加後のハッシュテーブル\nKey -> Value");
|
||||
map.Print();
|
||||
|
||||
/* 検索操作 */
|
||||
// キー key をハッシュテーブルに渡し、値 value を取得
|
||||
/* 取得操作 */
|
||||
// ハッシュテーブルにキー key を渡し、値 value を取得する
|
||||
string? name = map.Get(15937);
|
||||
Console.WriteLine("\n学籍番号 15937 を入力すると、氏名 " + name);
|
||||
Console.WriteLine("\n学生番号 15937 に対応する氏名は " + name);
|
||||
|
||||
/* 削除操作 */
|
||||
// ハッシュテーブルからキーと値のペア (key, value) を削除
|
||||
// ハッシュテーブルからキーと値のペア (key, value) を削除する
|
||||
map.Remove(10583);
|
||||
Console.WriteLine("\n10583 を削除した後、ハッシュテーブルは\nKey -> Value");
|
||||
Console.WriteLine("\n10583 を削除した後のハッシュテーブル\nKey -> Value");
|
||||
map.Print();
|
||||
|
||||
/* ハッシュテーブルを走査 */
|
||||
Console.WriteLine("\nキーと値のペア Key->Value を走査");
|
||||
/* ハッシュテーブルを走査する */
|
||||
Console.WriteLine("\nキーと値のペア Key->Value を走査する");
|
||||
foreach (Pair kv in map.PairSet()) {
|
||||
Console.WriteLine(kv.key + " -> " + kv.val);
|
||||
}
|
||||
Console.WriteLine("\nキー Key のみを走査");
|
||||
Console.WriteLine("\nキー Key だけを走査する");
|
||||
foreach (int key in map.KeySet()) {
|
||||
Console.WriteLine(key);
|
||||
}
|
||||
Console.WriteLine("\n値 Value のみを走査");
|
||||
Console.WriteLine("\n値 Value だけを走査する");
|
||||
foreach (string val in map.ValueSet()) {
|
||||
Console.WriteLine(val);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user