feat(heap): add go codes

This commit is contained in:
reanon
2023-01-12 20:32:06 +08:00
parent 92a80210f3
commit 32962fb7a1
4 changed files with 291 additions and 7 deletions
+16 -7
View File
@@ -29,6 +29,22 @@ func PrintList(list *list.List) {
fmt.Print(e.Value, "]\n")
}
// PrintMap Print a hash map
func PrintMap[K comparable, V any](m map[K]V) {
for key, value := range m {
fmt.Println(key, "->", value)
}
}
// PrintHeap Print a heap
func PrintHeap(h []any) {
fmt.Printf("堆的数组表示:")
fmt.Printf("%v", h)
fmt.Printf("\n堆的树状表示:\n")
root := ArrToTree(h)
PrintTree(root)
}
// PrintLinkedList Print a linked list
func PrintLinkedList(node *ListNode) {
if node == nil {
@@ -97,10 +113,3 @@ func showTrunk(t *trunk) {
showTrunk(t.prev)
fmt.Print(t.str)
}
// PrintMap Print a hash map
func PrintMap[K comparable, V any](m map[K]V) {
for key, value := range m {
fmt.Println(key, "->", value)
}
}