diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-24 18:15:52 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-24 18:15:52 +0100 |
| commit | a49c86ec981becac036f590362933f183f5d1234 (patch) | |
| tree | 2651b70f0ea53d4274674ffc7cf5bc0430e98147 /queue/elementarypriority.go | |
| parent | 44811a9f7bc84a642fd5805c964deb1ee7d134c5 (diff) | |
more on heapprio
Diffstat (limited to 'queue/elementarypriority.go')
| -rw-r--r-- | queue/elementarypriority.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/queue/elementarypriority.go b/queue/elementarypriority.go index 508cbcb..d5b3f4a 100644 --- a/queue/elementarypriority.go +++ b/queue/elementarypriority.go @@ -1,21 +1,21 @@ package queue -import "algorithms/ds" +import ( + "algorithms/ds" +) type ElementaryPriority struct { - a ds.ArrayList - size int + a ds.ArrayList // Initial capacity capacity int } func NewElementaryPriority(capacity int) *ElementaryPriority { - return &ElementaryPriority{make(ds.ArrayList, 0, capacity), 0, capacity} + return &ElementaryPriority{make(ds.ArrayList, 0, capacity), capacity} } func (q *ElementaryPriority) Insert(a int) { q.a = append(q.a, a) - q.size++ } func (q *ElementaryPriority) Max() (max int) { @@ -32,7 +32,7 @@ func (q *ElementaryPriority) DeleteMax() int { for i := ind + 1; i < q.Size(); i++ { q.a[i-1] = q.a[i] } - q.size-- + q.a = q.a[0 : len(q.a)-1] return max } @@ -42,11 +42,10 @@ func (q *ElementaryPriority) Empty() bool { } func (q *ElementaryPriority) Size() int { - return q.size + return len(q.a) } func (q *ElementaryPriority) Clear() { - q.size = 0 q.a = make(ds.ArrayList, 0, q.capacity) } |
