Skip to content

在泛型这一节中,堆的使用里面缺少NewHeap函数,补充了NewHeap函数 #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

这是一个简单纯粹且完全开源的 Golang 中文学习文档,网站内容是作者在学习过程中的记录,每一篇文章的更新都是新的积累,主要包括 go 语言基础方面的东西,适合入门玩家浏览。

由于作者水平十分有限,如果在文中有发现任何纰漏或者想自己发布文章,欢迎提交 issue 和 PR,有时间看到了会尽快审理。
由于作者水平十分有限,如果在文中有发现任何纰漏或者想自己发布文章,欢迎提交 issue 和 PR,有时间看到了会尽快审理。chr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的改动是干什么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry,自己的git出了点问题,我自己试git时候用的,我重新提交pr


## 开发

Expand Down
13 changes: 8 additions & 5 deletions src/essential/senior/90.generic.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
date: 2022-08-26
---

# 泛型

泛型,或者更学术化的名称 —— 参数化多态(Parameterized
Expand Down Expand Up @@ -250,10 +249,6 @@ func Assert[T any](v any) (bool, T) {
}
```





## 类型集

在 1.18 以后,接口的定义变为了类型集 `(type set)`,含有类型集的接口又称为 `General interfaces` 即通用接口。
Expand Down Expand Up @@ -724,6 +719,14 @@ func (heap *BinaryHeap[T]) down(i int) {
func (heap *BinaryHeap[T]) Size() int {
return len(heap.s)
}

func NewHeap[T any](n int, c Comparator[T]) BinaryHeap[T] {
var heap BinaryHeap[T]
heap.s = make([]T, 0, n)
heap.Comparator = c
return heap
}

```

使用起来如下
Expand Down
Loading