Skip to content

Commit

Permalink
Added a new constructor NewPQWithNumbers
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshputalapattu committed Sep 5, 2022
1 parent 4c3fc6b commit 1ab29e3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions heapq.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ func NewPQNumber[T Number]() *PQ[T] {
return pq
}

func NewPQWithNumbers[T Number](items []T) *PQ[T] {
pq := &PQ[T]{
queue: items,
Less: func(x, y T) bool {
return x < y
},
}

pq.init()
return pq

}

func (pq *PQ[T]) less(i, j int) bool {
return pq.Less(pq.queue[i], pq.queue[j])
}
Expand Down

0 comments on commit 1ab29e3

Please sign in to comment.