Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2. Algorithm heapify(A)
- 3. For i ← ⌊size of array A[ ]/2⌋-1 down to and including 0 do
- 4. maxHeapify(A, i)
- 5. End for
- 6. End
- 7.
- 8. Algorithm maxHeapify(A, n)
- 9. L ← 2i + 1
- 10. R ← 2i + 2
- 11. largest
- 12. If (hasLeft(A, n) and A[L] > A[n]) then
- 13. largest ← L
- 14. End if
- 15. Else
- 16. Largest ← n
- 17. End else
- 18. If (hasRight(A, n) and A[r] > A[largest])
- 19. Largest ← r
- 20. End if
- 21. If (largest ≠ n) then
- 22. Exchange A[n] with A[largest]
- 23. maxHeapify(A, largest)
- 24. End if
- 25. End
- 26.
- 27. public boolean hasLeft(A, n){
- 28. return 2i + 1 ≤ length of A
- 29. End if
- 30.
- 31. public Boolean hasRight(A, n)
- 32. return 2i + 2 ≤ length of A
- 33. End
- 34. D
- 35. Algorithm topFlyers(A)
- 36. Array result with the same size as the given array of passengers
- 37. for i ← 0 up to log n do
- 38. result[i] ← A[i]
- 39. End for
- 40. Return result
- 41. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement