Esempio n. 1
0
function heapsort(&$a)
{
    $heap_size = count($a);
    build_heap($a, $heap_size);
    while ($heap_size--) {
        $t = $a[$heap_size];
        $a[$heap_size] = $a[0];
        $a[0] = $t;
        build_heap($a, $heap_size);
    }
}
Esempio n. 2
0
function createHeap(&$array, $heapsize)
{
    $i = ceil($heapsize / 2) - 1;
    for (; $i >= 0; $i--) {
        build_heap($array, $i, $heapsize);
    }
}