Skip to content

Commit

Permalink
Add Max Heap Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
SitiNur committed Dec 15, 2014
1 parent 6cf16d8 commit aaf90b0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion MaxHeapTree.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ func (s String) Less(a interface{}) bool { return s < a.(String) }
type Heap struct {
data []Interface
}

// O(1)
func NewHeap() *Heap {
return &Heap{make([]Interface,0,0)}
}

// O(log n)
func (h *Heap) Push(data Interface) {
h.data = append(h.data,data)
cur := len(h.data)-1
Expand All @@ -31,6 +32,8 @@ func (h *Heap) Push(data Interface) {
}
}


// O(log n)
func (h *Heap) Pop() (data Interface, ok bool) {
if len(h.data) == 0 { return Int(0), false }
data, ok = h.data[0], true
Expand Down

0 comments on commit aaf90b0

Please sign in to comment.