mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-13 15:56:05 +00:00
Sort the coding languages by applications. (#721)
This commit is contained in:
@@ -62,12 +62,12 @@
|
||||
|
||||
在代码实现中,我们使用了与堆章节相同的从顶至底堆化 `sift_down()` 函数。值得注意的是,由于堆的长度会随着提取最大元素而减小,因此我们需要给 `sift_down()` 函数添加一个长度参数 $n$ ,用于指定堆的当前有效长度。
|
||||
|
||||
=== "Java"
|
||||
=== "Python"
|
||||
|
||||
```java title="heap_sort.java"
|
||||
[class]{heap_sort}-[func]{siftDown}
|
||||
```python title="heap_sort.py"
|
||||
[class]{}-[func]{sift_down}
|
||||
|
||||
[class]{heap_sort}-[func]{heapSort}
|
||||
[class]{}-[func]{heap_sort}
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
@@ -78,12 +78,20 @@
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
=== "Java"
|
||||
|
||||
```python title="heap_sort.py"
|
||||
[class]{}-[func]{sift_down}
|
||||
```java title="heap_sort.java"
|
||||
[class]{heap_sort}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heap_sort}
|
||||
[class]{heap_sort}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="heap_sort.cs"
|
||||
[class]{heap_sort}-[func]{siftDown}
|
||||
|
||||
[class]{heap_sort}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
@@ -94,6 +102,14 @@
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="heap_sort.swift"
|
||||
[class]{}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "JS"
|
||||
|
||||
```javascript title="heap_sort.js"
|
||||
@@ -110,38 +126,6 @@
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="heap_sort.c"
|
||||
[class]{}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="heap_sort.cs"
|
||||
[class]{heap_sort}-[func]{siftDown}
|
||||
|
||||
[class]{heap_sort}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="heap_sort.swift"
|
||||
[class]{}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="heap_sort.zig"
|
||||
[class]{}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Dart"
|
||||
|
||||
```dart title="heap_sort.dart"
|
||||
@@ -158,6 +142,22 @@
|
||||
[class]{}-[func]{heap_sort}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="heap_sort.c"
|
||||
[class]{}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="heap_sort.zig"
|
||||
[class]{}-[func]{siftDown}
|
||||
|
||||
[class]{}-[func]{heapSort}
|
||||
```
|
||||
|
||||
## 算法特性
|
||||
|
||||
- **时间复杂度 $O(n \log n)$、非自适应排序**:建堆操作使用 $O(n)$ 时间。从堆中提取最大元素的时间复杂度为 $O(\log n)$ ,共循环 $n - 1$ 轮。
|
||||
|
||||
Reference in New Issue
Block a user