Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function BuildMaxHeap(Int arr, Int n, String theKey)
- Int i = 1
- While (i < n)
- If (jMap.getFlt(jArray.getObj(arr, i), theKey) > jMap.getFlt(jArray.getObj(arr, (i - 1) / 2), theKey))
- Int j = i
- While (jMap.getFlt(jArray.getObj(arr, j), theKey) > jMap.getFlt(jArray.getObj(arr, (j - 1) / 2), theKey))
- jArray.swapItems(arr, j, (j - 1) / 2)
- j = (j - 1) / 2
- EndWhile
- EndIf
- i += 1
- EndWhile
- EndFunction
- Function IterativeHeapSort(Int arr, Int n, String theKey)
- BuildMaxHeap(arr, n, theKey)
- Int i = n - 1
- While (i > 0)
- jArray.swapItems(arr, 0, i)
- Int j = 0
- Int index
- Bool do = True ; Modified do-while
- While(do || index < 1)
- index = 2 * j + 1
- If (jMap.getFlt(jArray.getObj(arr, index), theKey) < jMap.getFlt(jArray.getObj(arr, index + 1), theKey) && index < (i - 1))
- index += 1
- EndIf
- If (jMap.getFlt(jArray.getObj(arr, j), theKey) < jMap.getFlt(jArray.getObj(arr, index), theKey) && index < i)
- jArray.swapItems(arr, j, index)
- EndIf
- j = index
- do = False
- EndWhile
- i -= 1
- EndWhile
- EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement