示例#1
0
<?php

class SplMinHeap2 extends SplMinHeap
{
    public function compare($a, $b)
    {
        return -parent::compare($a, $b);
    }
}
$h = new SplMinHeap2();
$h->insert(1);
$h->insert(6);
$h->insert(5);
$h->insert(2);
var_dump($h->top());
class SplMaxHeap2 extends SplMaxHeap
{
    public function compare($a, $b)
    {
        return -parent::compare($a, $b);
    }
}
$h = new SplMaxHeap2();
$h->insert(1);
$h->insert(6);
$h->insert(5);
$h->insert(2);
var_dump($h->top());
示例#2
0
<?php

$obj = new SplMaxHeap();
$obj->insert(1);
$obj->insert(2);
var_dump(count($obj));
class SplMaxHeap2 extends SplMaxHeap
{
    public function count()
    {
        return -parent::count();
    }
}
$obj = new SplMaxHeap2();
$obj->insert(1);
$obj->insert(2);
var_dump(count($obj));