+9
-6
@@ -19,9 +19,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func assertTreeImplementation() {
|
||||
var _ trees.Tree = (*Heap)(nil)
|
||||
}
|
||||
// Assert Tree implementation
|
||||
var _ trees.Tree = (*Heap)(nil)
|
||||
|
||||
// Heap holds elements in an array-list
|
||||
type Heap struct {
|
||||
@@ -98,15 +97,19 @@ func (heap *Heap) Clear() {
|
||||
|
||||
// Values returns all elements in the heap.
|
||||
func (heap *Heap) Values() []interface{} {
|
||||
return heap.list.Values()
|
||||
values := make([]interface{}, heap.list.Size(), heap.list.Size())
|
||||
for it := heap.Iterator(); it.Next(); {
|
||||
values[it.Index()] = it.Value()
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
// String returns a string representation of container
|
||||
func (heap *Heap) String() string {
|
||||
str := "BinaryHeap\n"
|
||||
values := []string{}
|
||||
for _, value := range heap.list.Values() {
|
||||
values = append(values, fmt.Sprintf("%v", value))
|
||||
for it := heap.Iterator(); it.Next(); {
|
||||
values = append(values, fmt.Sprintf("%v", it.Value()))
|
||||
}
|
||||
str += strings.Join(values, ", ")
|
||||
return str
|
||||
|
||||
Reference in New Issue
Block a user