summaryrefslogtreecommitdiff
path: root/queue/elementarypq.go
diff options
context:
space:
mode:
Diffstat (limited to 'queue/elementarypq.go')
-rw-r--r--queue/elementarypq.go60
1 files changed, 0 insertions, 60 deletions
diff --git a/queue/elementarypq.go b/queue/elementarypq.go
deleted file mode 100644
index b66d531..0000000
--- a/queue/elementarypq.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package queue
-
-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, capacity}
-}
-
-func (q *ElementaryPQ) Insert(a int) {
- q.a = append(q.a, a)
- q.size++
-}
-
-func (q *ElementaryPQ) Max() (max int) {
- _, max = q.max()
- return
-}
-
-func (q *ElementaryPQ) DeleteMax() int {
- if q.Empty() {
- return 0
- }
-
- ind, max := q.max()
- for i := ind + 1; i < q.Size(); i++ {
- q.a[i-1] = q.a[i]
- }
- q.size--
-
- return max
-}
-
-func (q *ElementaryPQ) Empty() bool {
- return q.Size() == 0
-}
-
-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 {
- ind, max = i, a
- }
- }
- return ind, max
-}