1. Add build script for Java.

2. Add height limitation for code blocks in extra.css.
3. Fix "节点" to "结点".
This commit is contained in:
krahets
2023-02-07 04:43:52 +08:00
parent b14568151c
commit ecbf2d1560
54 changed files with 457 additions and 1633 deletions

View File

@ -416,55 +416,9 @@ $$
=== "Java"
```java title="array_hash_map.java"
/* 键值对 int->String */
class Entry {
public int key; // 键
public String val; // 值
public Entry(int key, String val) {
this.key = key;
this.val = val;
}
}
/* 基于数组简易实现的哈希表 */
class ArrayHashMap {
private List<Entry> bucket;
public ArrayHashMap() {
// 初始化一个长度为 100 的桶(数组)
bucket = new ArrayList<>();
for (int i = 0; i < 100; i++) {
bucket.add(null);
}
}
/* 哈希函数 */
private int hashFunc(int key) {
int index = key % 100;
return index;
}
/* 查询操作 */
public String get(int key) {
int index = hashFunc(key);
Entry pair = bucket.get(index);
if (pair == null) return null;
return pair.val;
}
/* 添加操作 */
public void put(int key, String val) {
Entry pair = new Entry(key, val);
int index = hashFunc(key);
bucket.set(index, pair);
}
/* 删除操作 */
public void remove(int key) {
int index = hashFunc(key);
// 置为 null代表删除
bucket.set(index, null);
}
}
[class]{Entry}-[func]{}
[class]{ArrayHashMap}-[func]{}
```
=== "C++"