mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-27 15:02:16 +08:00
Fix demo comments and labels that contradict the code (#2048)
Fix Chinese wording that contradicted the demo code: the C++ std::hash scope, the Rust node-value hash label, the Go Pop comment and the Go stack test comment. Russian sources and all six editions' snippets follow; the Go heap snippets drop the repository-only PrintHeap call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,6 @@ int main() {
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "字符串 " << str << " 的哈希值为 " << hashStr << "\n";
|
||||
|
||||
// 在 C++ 中,内置 std::hash() 仅提供基本数据类型的哈希值计算
|
||||
// 在 C++ 中,内置 std::hash() 仅提供基本数据类型和部分标准库类型(如 std::string)的哈希值计算
|
||||
// 数组、对象的哈希值计算需要自行实现
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop heap.Interface 的函数,实现弹出堆顶元素
|
||||
// Pop heap.Interface 的函数,弹出切片末尾元素(heap.Pop 已将堆顶元素交换至末尾)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 待出堆元素存放在最后
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h *minHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop heap.Interface 的方法,实现弹出堆顶元素
|
||||
// Pop heap.Interface 的方法,弹出切片末尾元素(heap.Pop 已将堆顶元素交换至末尾)
|
||||
func (h *minHeap) Pop() any {
|
||||
// 待出堆元素存放在最后
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestStack(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayStack(t *testing.T) {
|
||||
// 初始化栈, 使用接口承接
|
||||
// 初始化栈
|
||||
stack := newArrayStack()
|
||||
|
||||
// 元素入栈
|
||||
|
||||
@@ -45,5 +45,5 @@ fn main() {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
println!("节点对象 {:?} 的哈希值为 {}", node, hash);
|
||||
println!("节点 {:?} 中节点值的哈希值为 {}", node, hash);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ size_t hashStr = hash<string>()(str);
|
||||
cout << "字符串“" << str << "”的哈希值为 " << hashStr << "\n";
|
||||
// 字符串“Hello 算法”的哈希值为 15466937326284535026
|
||||
|
||||
// 在 C++ 中,内置 std::hash() 仅提供基本数据类型的哈希值计算
|
||||
// 在 C++ 中,内置 std::hash() 仅提供基本数据类型和部分标准库类型(如 std::string)的哈希值计算
|
||||
// 数组、对象的哈希值计算需要自行实现
|
||||
```
|
||||
|
||||
@@ -239,8 +239,8 @@ let node = ListNode::new(42);
|
||||
let mut node_hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut node_hasher);
|
||||
let hash_node = node_hasher.finish();
|
||||
println!("节点对象 {:?} 的哈希值为 {}", node, hash_node);
|
||||
// 节点对象 RefCell { value: ListNode { val: 42, next: None } } 的哈希值为 15387811073369036852
|
||||
println!("节点 {:?} 中节点值的哈希值为 {}", node, hash_node);
|
||||
// 节点 RefCell { value: ListNode { val: 42, next: None } } 中节点值的哈希值为 15387811073369036852
|
||||
```
|
||||
|
||||
```c title="built_in_hash.c"
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop heap.Interface 的函数,实现弹出堆顶元素
|
||||
// Pop heap.Interface 的函数,弹出切片末尾元素(heap.Pop 已将堆顶元素交换至末尾)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 待出堆元素存放在最后
|
||||
last := (*h)[len(*h)-1]
|
||||
@@ -201,7 +201,6 @@ func TestHeap(t *testing.T) {
|
||||
heap.Push(maxHeap, 2)
|
||||
heap.Push(maxHeap, 5)
|
||||
heap.Push(maxHeap, 4)
|
||||
PrintHeap(*maxHeap)
|
||||
|
||||
/* 获取堆顶元素 */
|
||||
top := maxHeap.Top()
|
||||
|
||||
@@ -24,6 +24,6 @@ int main() {
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "String " << str << " has hash value " << hashStr << "\n";
|
||||
|
||||
// In C++, the built-in std::hash() only computes hash values for basic data types
|
||||
// In C++, the built-in std::hash() only computes hash values for basic data types and some standard library types (such as std::string)
|
||||
// Hashing arrays and objects requires a custom implementation
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop is a heap.Interface function that pops the top element from the heap
|
||||
// Pop is a heap.Interface function that pops the last element from the slice (heap.Pop has already swapped the top element of the heap to the end)
|
||||
func (h *intHeap) Pop() any {
|
||||
// The element to remove is stored at the end
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h *minHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop implements heap.Interface by removing the last element, where heap.Pop has moved the top element
|
||||
// Pop is a heap.Interface method that pops the last element from the slice (heap.Pop has already swapped the top element of the heap to the end)
|
||||
func (h *minHeap) Pop() any {
|
||||
// The element to remove is stored at the end
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestStack(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayStack(t *testing.T) {
|
||||
// Initialize the stack and assign it to an interface
|
||||
// Initialize the stack
|
||||
stack := newArrayStack()
|
||||
|
||||
// Push elements onto the stack
|
||||
|
||||
@@ -45,5 +45,5 @@ fn main() {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
println!("Node object {:?} has hash value {}", node, hash);
|
||||
println!("The value in node {:?} has hash value {}", node, hash);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ size_t hashStr = hash<string>()(str);
|
||||
cout << "String '" << str << "' has hash value " << hashStr << "\n";
|
||||
// String 'Hello 算法' has hash value 15466937326284535026
|
||||
|
||||
// In C++, the built-in std::hash() only computes hash values for basic data types
|
||||
// In C++, the built-in std::hash() only computes hash values for basic data types and some standard library types (such as std::string)
|
||||
// Hashing arrays and objects requires a custom implementation
|
||||
```
|
||||
|
||||
@@ -239,8 +239,8 @@ let node = ListNode::new(42);
|
||||
let mut node_hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut node_hasher);
|
||||
let hash_node = node_hasher.finish();
|
||||
println!("Node object {:?} has hash value {}", node, hash_node);
|
||||
// Node object RefCell { value: ListNode { val: 42, next: None } } has hash value 15387811073369036852
|
||||
println!("The value in node {:?} has hash value {}", node, hash_node);
|
||||
// The value in node RefCell { value: ListNode { val: 42, next: None } } has hash value 15387811073369036852
|
||||
```
|
||||
|
||||
```c title="built_in_hash.c"
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop is a heap.Interface function that pops the top element from the heap
|
||||
// Pop is a heap.Interface function that pops the last element from the slice (heap.Pop has already swapped the top element of the heap to the end)
|
||||
func (h *intHeap) Pop() any {
|
||||
// The element to remove is stored at the end
|
||||
last := (*h)[len(*h)-1]
|
||||
@@ -201,7 +201,6 @@ func TestHeap(t *testing.T) {
|
||||
heap.Push(maxHeap, 2)
|
||||
heap.Push(maxHeap, 5)
|
||||
heap.Push(maxHeap, 4)
|
||||
PrintHeap(*maxHeap)
|
||||
|
||||
/* Get the top element of the heap */
|
||||
top := maxHeap.Top()
|
||||
|
||||
@@ -24,6 +24,6 @@ int main() {
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "文字列 " << str << " のハッシュ値は " << hashStr << "\n";
|
||||
|
||||
// C++ の組み込み std::hash() は、基本データ型のハッシュ値の計算にのみ対応する
|
||||
// C++ の組み込み std::hash() は、基本データ型と標準ライブラリの一部の型(std::string など)のハッシュ値の計算にのみ対応する
|
||||
// 配列やオブジェクトのハッシュ値の計算は自分で実装する必要がある
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop は heap.Interface の関数であり、ヒープの先頭要素の取り出しを実装する
|
||||
// Pop は heap.Interface の関数であり、スライスの末尾要素を取り出す(heap.Pop がすでにヒープの先頭要素と末尾要素を交換している)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 取り出す要素は末尾に格納されている
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h *minHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop は heap.Interface のメソッドであり、ヒープの先頭要素の取り出しを実装する
|
||||
// Pop は heap.Interface のメソッドであり、スライスの末尾要素を取り出す(heap.Pop がすでにヒープの先頭要素と末尾要素を交換している)
|
||||
func (h *minHeap) Pop() any {
|
||||
// 取り出す要素は末尾に格納されている
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestStack(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayStack(t *testing.T) {
|
||||
// スタックを初期化し、インターフェースで受け取る
|
||||
// スタックを初期化する
|
||||
stack := newArrayStack()
|
||||
|
||||
// 要素をプッシュする
|
||||
|
||||
@@ -45,5 +45,5 @@ fn main() {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
println!("ノードオブジェクト {:?} のハッシュ値は {}", node, hash);
|
||||
println!("ノード {:?} の値のハッシュ値は {}", node, hash);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ size_t hashStr = hash<string>()(str);
|
||||
cout << "文字列「" << str << "」のハッシュ値は " << hashStr << "\n";
|
||||
// 文字列「Hello 算法」のハッシュ値は 15466937326284535026
|
||||
|
||||
// C++ の組み込み std::hash() は、基本データ型のハッシュ値の計算にのみ対応する
|
||||
// C++ の組み込み std::hash() は、基本データ型と標準ライブラリの一部の型(std::string など)のハッシュ値の計算にのみ対応する
|
||||
// 配列やオブジェクトのハッシュ値の計算は自分で実装する必要がある
|
||||
```
|
||||
|
||||
@@ -239,8 +239,8 @@ let node = ListNode::new(42);
|
||||
let mut node_hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut node_hasher);
|
||||
let hash_node = node_hasher.finish();
|
||||
println!("ノードオブジェクト {:?} のハッシュ値は {}", node, hash_node);
|
||||
// ノードオブジェクト RefCell { value: ListNode { val: 42, next: None } } のハッシュ値は 15387811073369036852
|
||||
println!("ノード {:?} の値のハッシュ値は {}", node, hash_node);
|
||||
// ノード RefCell { value: ListNode { val: 42, next: None } } の値のハッシュ値は 15387811073369036852
|
||||
```
|
||||
|
||||
```c title="built_in_hash.c"
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop は heap.Interface の関数であり、ヒープの先頭要素の取り出しを実装する
|
||||
// Pop は heap.Interface の関数であり、スライスの末尾要素を取り出す(heap.Pop がすでにヒープの先頭要素と末尾要素を交換している)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 取り出す要素は末尾に格納されている
|
||||
last := (*h)[len(*h)-1]
|
||||
@@ -201,7 +201,6 @@ func TestHeap(t *testing.T) {
|
||||
heap.Push(maxHeap, 2)
|
||||
heap.Push(maxHeap, 5)
|
||||
heap.Push(maxHeap, 4)
|
||||
PrintHeap(*maxHeap)
|
||||
|
||||
/* ヒープの先頭要素を取得する */
|
||||
top := maxHeap.Top()
|
||||
|
||||
@@ -24,6 +24,6 @@ int main() {
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "문자열 " << str << " → 해시값: " << hashStr << "\n";
|
||||
|
||||
// C++의 내장 std::hash()는 기본 데이터 타입에 대한 해시값 계산만 제공한다
|
||||
// C++의 내장 std::hash()는 기본 데이터 타입과 일부 표준 라이브러리 타입(예: std::string)에 대한 해시값 계산만 제공한다
|
||||
// 배열과 객체의 해시값 계산은 직접 구현해야 한다
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop: heap.Interface의 함수로, 힙의 루트 원소를 꺼낸다
|
||||
// Pop: heap.Interface의 함수로, 슬라이스의 마지막 원소를 꺼낸다(heap.Pop이 이미 힙의 루트 원소를 교환하여 맨 뒤로 옮겼다)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 꺼낼 원소는 맨 마지막에 저장되어 있다
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h *minHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop: heap.Interface의 메서드로, 힙의 루트 원소를 꺼낸다
|
||||
// Pop: heap.Interface의 메서드로, 슬라이스의 마지막 원소를 꺼낸다(heap.Pop이 이미 힙의 루트 원소를 교환하여 맨 뒤로 옮겼다)
|
||||
func (h *minHeap) Pop() any {
|
||||
// 꺼낼 원소는 맨 마지막에 저장되어 있다
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestStack(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayStack(t *testing.T) {
|
||||
// 스택을 초기화하고 인터페이스로 받는다
|
||||
// 스택 초기화
|
||||
stack := newArrayStack()
|
||||
|
||||
// 스택에 원소 삽입
|
||||
|
||||
@@ -45,5 +45,5 @@ fn main() {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
println!("노드 객체 {:?} → 해시값: {}", node, hash);
|
||||
println!("노드 {:?}의 값 → 해시값: {}", node, hash);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ size_t hashStr = hash<string>()(str);
|
||||
cout << "문자열 ‘" << str << "’ → 해시값: " << hashStr << "\n";
|
||||
// 문자열 ‘Hello 算法’ → 해시값: 15466937326284535026
|
||||
|
||||
// C++의 내장 std::hash()는 기본 데이터 타입에 대한 해시값 계산만 제공한다
|
||||
// C++의 내장 std::hash()는 기본 데이터 타입과 일부 표준 라이브러리 타입(예: std::string)에 대한 해시값 계산만 제공한다
|
||||
// 배열과 객체의 해시값 계산은 직접 구현해야 한다
|
||||
```
|
||||
|
||||
@@ -239,8 +239,8 @@ let node = ListNode::new(42);
|
||||
let mut node_hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut node_hasher);
|
||||
let hash_node = node_hasher.finish();
|
||||
println!("노드 객체 {:?} → 해시값: {}", node, hash_node);
|
||||
// 노드 객체 RefCell { value: ListNode { val: 42, next: None } } → 해시값: 15387811073369036852
|
||||
println!("노드 {:?}의 값 → 해시값: {}", node, hash_node);
|
||||
// 노드 RefCell { value: ListNode { val: 42, next: None } }의 값 → 해시값: 15387811073369036852
|
||||
```
|
||||
|
||||
```c title="built_in_hash.c"
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop: heap.Interface의 함수로, 힙의 루트 원소를 꺼낸다
|
||||
// Pop: heap.Interface의 함수로, 슬라이스의 마지막 원소를 꺼낸다(heap.Pop이 이미 힙의 루트 원소를 교환하여 맨 뒤로 옮겼다)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 꺼낼 원소는 맨 마지막에 저장되어 있다
|
||||
last := (*h)[len(*h)-1]
|
||||
@@ -201,7 +201,6 @@ func TestHeap(t *testing.T) {
|
||||
heap.Push(maxHeap, 2)
|
||||
heap.Push(maxHeap, 5)
|
||||
heap.Push(maxHeap, 4)
|
||||
PrintHeap(*maxHeap)
|
||||
|
||||
/* 힙의 루트 원소 반환 */
|
||||
top := maxHeap.Top()
|
||||
|
||||
@@ -24,6 +24,6 @@ int main() {
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "Хеш-значение строки " << str << " = " << hashStr << "\n";
|
||||
|
||||
// В C++ встроенный std::hash() предоставляет вычисление хеша только для базовых типов данных
|
||||
// В C++ встроенный std::hash() предоставляет вычисление хеша только для базовых типов данных и некоторых типов стандартной библиотеки (например, std::string)
|
||||
// Вычисление хеша для массивов и объектов нужно реализовывать самостоятельно
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Функция Pop интерфейса heap.Interface, реализующая извлечение элемента с вершины кучи
|
||||
// Функция Pop интерфейса heap.Interface: извлекает последний элемент среза (heap.Pop заранее перемещает вершину кучи в конец)
|
||||
func (h *intHeap) Pop() any {
|
||||
// Элемент, который нужно удалить из кучи, хранится в конце
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h *minHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Метод Pop интерфейса heap.Interface, реализующий извлечение элемента с вершины кучи
|
||||
// Метод Pop интерфейса heap.Interface: извлекает последний элемент среза (heap.Pop заранее перемещает вершину кучи в конец)
|
||||
func (h *minHeap) Pop() any {
|
||||
// Элемент, который нужно удалить из кучи, хранится в конце
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestStack(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayStack(t *testing.T) {
|
||||
// Инициализировать стек, используя интерфейс
|
||||
// Инициализировать стек
|
||||
stack := newArrayStack()
|
||||
|
||||
// Помещение элемента в стек
|
||||
|
||||
@@ -45,5 +45,5 @@ fn main() {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
println!("Хеш-значение объекта узла {:?} = {}", node, hash);
|
||||
println!("Хеш-значение значения в узле {:?} = {}", node, hash);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ size_t hashStr = hash<string>()(str);
|
||||
cout << "Хеш-значение строки «" << str << "» = " << hashStr << "\n";
|
||||
// Хеш-значение строки «Hello Algo» = 15466937326284535026
|
||||
|
||||
// В C++ встроенный std::hash() предоставляет вычисление хеша только для базовых типов данных
|
||||
// В C++ встроенный std::hash() предоставляет вычисление хеша только для базовых типов данных и некоторых типов стандартной библиотеки (например, std::string)
|
||||
// Вычисление хеша для массивов и объектов нужно реализовывать самостоятельно
|
||||
```
|
||||
|
||||
@@ -239,8 +239,8 @@ let node = ListNode::new(42);
|
||||
let mut node_hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut node_hasher);
|
||||
let hash_node = node_hasher.finish();
|
||||
println!("Хеш-значение объекта узла {:?} = {}", node, hash_node);
|
||||
// Хеш-значение объекта узла RefCell { value: ListNode { val: 42, next: None } } = 15387811073369036852
|
||||
println!("Хеш-значение значения в узле {:?} = {}", node, hash_node);
|
||||
// Хеш-значение значения в узле RefCell { value: ListNode { val: 42, next: None } } = 15387811073369036852
|
||||
```
|
||||
|
||||
```c title="built_in_hash.c"
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Функция Pop интерфейса heap.Interface, реализующая извлечение элемента с вершины кучи
|
||||
// Функция Pop интерфейса heap.Interface: извлекает последний элемент среза (heap.Pop заранее перемещает вершину кучи в конец)
|
||||
func (h *intHeap) Pop() any {
|
||||
// Элемент, который нужно удалить из кучи, хранится в конце
|
||||
last := (*h)[len(*h)-1]
|
||||
@@ -201,7 +201,6 @@ func TestHeap(t *testing.T) {
|
||||
heap.Push(maxHeap, 2)
|
||||
heap.Push(maxHeap, 5)
|
||||
heap.Push(maxHeap, 4)
|
||||
PrintHeap(*maxHeap)
|
||||
|
||||
/* Получение элемента с вершины кучи */
|
||||
top := maxHeap.Top()
|
||||
|
||||
@@ -24,6 +24,6 @@ int main() {
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "字串 " << str << " 的雜湊值為 " << hashStr << "\n";
|
||||
|
||||
// 在 C++ 中,內建 std::hash() 僅提供基本資料型別的雜湊值計算
|
||||
// 在 C++ 中,內建 std::hash() 僅提供基本資料型別和部分標準庫型別(如 std::string)的雜湊值計算
|
||||
// 陣列、物件的雜湊值計算需要自行實現
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop heap.Interface 的函式,實現彈出堆積頂元素
|
||||
// Pop heap.Interface 的函式,彈出切片末尾元素(heap.Pop 已將堆積頂元素交換至末尾)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 待出堆積元素存放在最後
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h *minHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop heap.Interface 的方法,實現彈出堆積頂元素
|
||||
// Pop heap.Interface 的方法,彈出切片末尾元素(heap.Pop 已將堆積頂元素交換至末尾)
|
||||
func (h *minHeap) Pop() any {
|
||||
// 待出堆積元素存放在最後
|
||||
last := (*h)[len(*h)-1]
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestStack(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayStack(t *testing.T) {
|
||||
// 初始化堆疊, 使用介面承接
|
||||
// 初始化堆疊
|
||||
stack := newArrayStack()
|
||||
|
||||
// 元素入堆疊
|
||||
|
||||
@@ -45,5 +45,5 @@ fn main() {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
println!("節點物件 {:?} 的雜湊值為 {}", node, hash);
|
||||
println!("節點 {:?} 中節點值的雜湊值為 {}", node, hash);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ size_t hashStr = hash<string>()(str);
|
||||
cout << "字串“" << str << "”的雜湊值為 " << hashStr << "\n";
|
||||
// 字串“Hello 演算法”的雜湊值為 15466937326284535026
|
||||
|
||||
// 在 C++ 中,內建 std::hash() 僅提供基本資料型別的雜湊值計算
|
||||
// 在 C++ 中,內建 std::hash() 僅提供基本資料型別和部分標準庫型別(如 std::string)的雜湊值計算
|
||||
// 陣列、物件的雜湊值計算需要自行實現
|
||||
```
|
||||
|
||||
@@ -75,7 +75,7 @@ System.out.println("小數 " + dec + " 的雜湊值為 " + hashDec);
|
||||
String str = "Hello 演算法";
|
||||
int hashStr = str.hashCode();
|
||||
System.out.println("字串“" + str + "”的雜湊值為 " + hashStr);
|
||||
// 字串“Hello 演算法”的雜湊值為 -727081396
|
||||
// 字串“Hello 演算法”的雜湊值為 -1067619900
|
||||
|
||||
Object[] arr = { 12836, "小哈" };
|
||||
int hashArr = Arrays.hashCode(arr);
|
||||
@@ -183,7 +183,7 @@ print("小數 $dec 的雜湊值為 $hashDec");
|
||||
String str = "Hello 演算法";
|
||||
int hashStr = str.hashCode;
|
||||
print("字串“$str”的雜湊值為 $hashStr");
|
||||
// 字串“Hello 演算法”的雜湊值為 468167534
|
||||
// 字串“Hello 演算法”的雜湊值為 544745643
|
||||
|
||||
List arr = [12836, "小哈"];
|
||||
int hashArr = arr.hashCode;
|
||||
@@ -226,7 +226,7 @@ let mut str_hasher = DefaultHasher::new();
|
||||
str.hash(&mut str_hasher);
|
||||
let hash_str = str_hasher.finish();
|
||||
println!("字串“{}”的雜湊值為 {}", str, hash_str);
|
||||
// 字串“Hello 演算法”的雜湊值為 16092673739211250988
|
||||
// 字串“Hello 演算法”的雜湊值為 14554651044579956997
|
||||
|
||||
let tup = (&12836, &"小哈");
|
||||
let mut tup_hasher = DefaultHasher::new();
|
||||
@@ -239,8 +239,8 @@ let node = ListNode::new(42);
|
||||
let mut node_hasher = DefaultHasher::new();
|
||||
node.borrow().val.hash(&mut node_hasher);
|
||||
let hash_node = node_hasher.finish();
|
||||
println!("節點物件 {:?} 的雜湊值為 {}", node, hash_node);
|
||||
// 節點物件 RefCell { value: ListNode { val: 42, next: None } } 的雜湊值為 15387811073369036852
|
||||
println!("節點 {:?} 中節點值的雜湊值為 {}", node, hash_node);
|
||||
// 節點 RefCell { value: ListNode { val: 42, next: None } } 中節點值的雜湊值為 15387811073369036852
|
||||
```
|
||||
|
||||
```c title="built_in_hash.c"
|
||||
@@ -266,7 +266,7 @@ println("小數 $dec 的雜湊值為 $hashDec")
|
||||
val str = "Hello 演算法"
|
||||
val hashStr = str.hashCode()
|
||||
println("字串“$str”的雜湊值為 $hashStr")
|
||||
// 字串“Hello 演算法”的雜湊值為 -727081396
|
||||
// 字串“Hello 演算法”的雜湊值為 -1067619900
|
||||
|
||||
val arr = arrayOf<Any>(12836, "小哈")
|
||||
val hashArr = arr.contentHashCode()
|
||||
|
||||
@@ -160,7 +160,7 @@ func (h *intHeap) Push(x any) {
|
||||
*h = append(*h, x.(int))
|
||||
}
|
||||
|
||||
// Pop heap.Interface 的函式,實現彈出堆積頂元素
|
||||
// Pop heap.Interface 的函式,彈出切片末尾元素(heap.Pop 已將堆積頂元素交換至末尾)
|
||||
func (h *intHeap) Pop() any {
|
||||
// 待出堆積元素存放在最後
|
||||
last := (*h)[len(*h)-1]
|
||||
@@ -201,7 +201,6 @@ func TestHeap(t *testing.T) {
|
||||
heap.Push(maxHeap, 2)
|
||||
heap.Push(maxHeap, 5)
|
||||
heap.Push(maxHeap, 4)
|
||||
PrintHeap(*maxHeap)
|
||||
|
||||
/* 獲取堆積頂元素 */
|
||||
top := maxHeap.Top()
|
||||
|
||||
Reference in New Issue
Block a user