Compare commits

...

2 Commits

Author SHA1 Message Date
Acid cd6c8973da heap sort
Go / build (push) Successful in 23s
new file:   trees/heap/heapAlgorithms.go
2026-07-13 23:35:34 -04:00
Acid db7976f65a heap sort added 2026-07-13 23:35:11 -04:00
2 changed files with 31 additions and 0 deletions
+1
View File
@@ -25,6 +25,7 @@
- [x] Kadane's Algorithm
- [x] Euclidean gcd
- [x] Fibonacci
- [x] Heap Sort
- [ ] Modular Arithmetic
- [ ] Sieve of Eratosthenes
- [x] BFS Breadth-First Search
+30
View File
@@ -0,0 +1,30 @@
package heap
import (
"cmp"
)
// HeapSrort() -> takes in an array and returns it sorted. O(n log n)
func HeapSrort[T cmp.Ordered](arg []T) []T {
if len(arg) <= 0 {
return nil
}
heap := NewMinHeap[T]()
heap.Heapify(arg)
sorted := make([]T, 0, len(arg))
for range heap.Array {
val, ok := heap.PopMin()
if !ok {
break
}
sorted = append(sorted, val)
}
return sorted
}