Sorting algorithms/Heapsort: Difference between revisions

Content added Content deleted
Line 2,545: Line 2,545:
</pre>
</pre>
=={{header|PowerShell}}==
=={{header|PowerShell}}==

{{works with|PowerShell|4.0}}

<lang PowerShell>
<lang PowerShell>
function heapsort($a, $count) {
function heapsort($a, $count) {
Line 2,553: Line 2,550:
$end = $count - 1
$end = $count - 1
while( $end -gt 0) {
while( $end -gt 0) {
$temp = $a[$end]
$a[$end], $a[0] = $a[0], $a[$end]
$a[$end] = $a[0]
$a[0] = $temp
$end--
$end--
$a = siftDown $a 0 $end
$a = siftDown $a 0 $end
Line 2,576: Line 2,571:
$child++
$child++
}
}
if($a[$root] -lt $a[$child]) {
if($a[$root] -lt $a[$child]) {
$temp = $a[$root]
$a[$root], $a[$child] = $a[$child], $a[$root]
$a[$root] = $a[$child]
$a[$child] = $temp
$root = $child
$root = $child
}
}
Line 2,593: Line 2,586:
3 8 11 19 21 36 60 63 80 87 100
3 8 11 19 21 36 60 63 80 87 100
</pre>
</pre>

=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Declare heapify(Array a(1), count)
<lang PureBasic>Declare heapify(Array a(1), count)