Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public heap(){
- Public void maxHeapify(A, n){
- L → 2i + 1
- R → 2i + 2
- largest
- If (hasLeft(A, n) && A[L] > A[n])
- largest = L
- End
- Else
- Largest = n
- End
- If (hasRight(A, n) && A[r] > A[largest])
- Largest = r
- End
- If (largest ≠ n)
- Exchange A[n] with A[largest]
- maxHeapify(A, largest)
- public boolean hasLeft(A, n){
- return 2i + 1 ≤ length of A
- public Boolean hasRight(A, n)
- return 2i + 2 ≤ length of A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement