Skip to content

Commit 3df3599

Browse files
lhauspietheodesp
authored andcommitted
feat(leftist heap): change test to fit exampl and then fix the test (#38)
Ta!
1 parent cfbb225 commit 3df3599

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

leftist/leftist_heap.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func merge(x, y *Node) *Node {
5454

5555
// Init initializes or clears the LeftistHeap
5656
func (h *LeftistHeap) Init() *LeftistHeap {
57-
h.root = &Node{}
57+
h.root = nil
5858
return h
5959
}
6060

@@ -84,6 +84,9 @@ func (h *LeftistHeap) DeleteMin() heap.Item {
8484
// FindMin finds the minimum value.
8585
// The complexity is O(1).
8686
func (h *LeftistHeap) FindMin() heap.Item {
87+
if h.root == nil {
88+
return nil
89+
}
8790
return h.root.item
8891
}
8992

leftist/leftist_heap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestLeftistHeapInteger(t *testing.T) {
11-
heap := &LeftistHeap{}
11+
heap := New().Init()
1212

1313
numbers := []int{4, 3, 2, 5}
1414

0 commit comments

Comments
 (0)