Advertisement
joharido

Untitled

Mar 13th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. Public heap(){
  2. Public void maxHeapify(A, n){
  3. L → 2i + 1
  4. R → 2i + 2
  5. largest
  6. If (hasLeft(A, n) && A[L] > A[n])
  7. largest = L
  8. End
  9. Else
  10. Largest = n
  11. End
  12. If (hasRight(A, n) && A[r] > A[largest])
  13. Largest = r
  14. End
  15. If (largest ≠ n)
  16. Exchange A[n] with A[largest]
  17. maxHeapify(A, largest)
  18. public boolean hasLeft(A, n){
  19. return 2i + 1 ≤ length of A
  20. public Boolean hasRight(A, n)
  21. return 2i + 2 ≤ length of A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement