summaryrefslogtreecommitdiff
path: root/queue/elementarypq.go
diff options
context:
space:
mode:
Diffstat (limited to 'queue/elementarypq.go')
-rw-r--r--queue/elementarypq.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/queue/elementarypq.go b/queue/elementarypq.go
index 31cab9f..1155cb4 100644
--- a/queue/elementarypq.go
+++ b/queue/elementarypq.go
@@ -5,10 +5,12 @@ import "algorithms/ds"
type ElementaryPQ struct {
a ds.ArrayList
size int
+ // Initial capacity
+ capacity int
}
func NewElementaryPQ(capacity int) ElementaryPQ {
- return ElementaryPQ{make(ds.ArrayList, 0, capacity), 0}
+ return ElementaryPQ{make(ds.ArrayList, 0, capacity), 0, capacity}
}
func (q ElementaryPQ) Insert(a int) {
@@ -43,6 +45,11 @@ func (q ElementaryPQ) Size() int {
return q.size
}
+func (q ElementaryPQ) Clear() {
+ q.size = 0
+ q.a = make(ds.ArrayList, 0, q.capacity)
+}
+
func (q ElementaryPQ) max() (ind, max int) {
for i, a := range q.a {
if a > max {