You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current removal method doesn't properly remove an element from the storage array.
Example if the heap is [ 0, 1, 5, 15, 45, 14, 10, 34 ]
calling removeMin results in [1, 15, 5, 34, 45, 14, 10, 34]
I fixed this by adding this.storage.pop() to the remove min method so that it correctly returns [1, 15, 5, 34, 45, 14, 10]
new removeMin code
removeMin(){
if(this.size === 0){
throw new Error("Empty Heap")
}
let data = this.storage[0]
this.storage[0] = this.storage[this.size -1]
this.storage.pop()
this.size -= 1
this.heapifyDown(0)
return data
}
Can I make a pull request with these changes?
The text was updated successfully, but these errors were encountered:
The current removal method doesn't properly remove an element from the storage array.
Example if the heap is [ 0, 1, 5, 15, 45, 14, 10, 34 ]
calling removeMin results in [1, 15, 5, 34, 45, 14, 10, 34]
I fixed this by adding this.storage.pop() to the remove min method so that it correctly returns [1, 15, 5, 34, 45, 14, 10]
new removeMin code
Can I make a pull request with these changes?
The text was updated successfully, but these errors were encountered: