Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TrickleDown (i)
- - - i is the position in the array
- if i is on a min level then
- TrickleDownMin(i)
- else
- TrickleDownMax(i)
- endif
- procedure TrickleDownMin(i)
- if A[i] has children then
- m := index of smallest of the
- children and grandchildren
- (if any) of A[i]
- if A[m] is a grandchild of A[i] then
- if A[m] < A[i] then
- swap A[i] and A[m]
- if A[m] > A[parent(m)] then
- swap A[m] and A[parent(m)]
- endif
- TrickleDownMin(m)
- endif
- else {A[m] is a child of A[i]]
- if A[m] < A[i] then
- swap A[i] and A[m]
- endif
- endif
- procedure TrickleDownMax(i)
- if A[i] has children then
- m := index of smallest of the
- children and grandchildren
- (if any) of A[i]
- if A[m] is a grandchild of A[i] then
- if A[m] > A[i] then
- swap A[i] and A[m]
- if A[m] < A[parent(m)] then
- swap A[m] and A[parent(m)]
- endif
- TrickleDownMax(m)
- endif
- else {A[m] is a child of A[i]]
- if A[m] > A[i] then
- swap A[i] and A[m]
- endif
- endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement