Advertisement
Sirallens

Untitled

Dec 2nd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. procedure TrickleDown (i)
  2. - - i is the position in the array
  3. if i is on a min level then
  4. TrickleDownMin(i)
  5. else
  6. TrickleDownMax(i)
  7. endif
  8.  
  9.  
  10.  
  11. procedure TrickleDownMin(i)
  12.  
  13. if A[i] has children then
  14. m := index of smallest of the
  15. children and grandchildren
  16. (if any) of A[i]
  17. if A[m] is a grandchild of A[i] then
  18. if A[m] < A[i] then
  19. swap A[i] and A[m]
  20. if A[m] > A[parent(m)] then
  21. swap A[m] and A[parent(m)]
  22. endif
  23. TrickleDownMin(m)
  24. endif
  25. else {A[m] is a child of A[i]]
  26. if A[m] < A[i] then
  27. swap A[i] and A[m]
  28. endif
  29. endif
  30.  
  31.  
  32.  
  33.  
  34. procedure TrickleDownMax(i)
  35.  
  36. if A[i] has children then
  37. m := index of smallest of the
  38. children and grandchildren
  39. (if any) of A[i]
  40. if A[m] is a grandchild of A[i] then
  41. if A[m] > A[i] then
  42. swap A[i] and A[m]
  43. if A[m] < A[parent(m)] then
  44. swap A[m] and A[parent(m)]
  45. endif
  46. TrickleDownMax(m)
  47. endif
  48. else {A[m] is a child of A[i]]
  49. if A[m] > A[i] then
  50. swap A[i] and A[m]
  51. endif
  52. endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement