<?php $h = new SplMaxHeap(); $h->insert(1); $h->insert(5); $h->insert(0); $h->insert(4); $h->rewind(); echo "count(\$h) = " . count($h) . "\n"; echo "\$h->count() = " . $h->count() . "\n"; while ($h->valid()) { $k = $h->key(); $v = $h->current(); echo "{$k}=>{$v}\n"; $h->next(); } ?> ===DONE===
//$heap->insert('E', '4'); // isEmpty() // 判断该堆是否为空 $heap->isEmpty(); // count() // 获得堆值的数量 $heap->count(); // key() // 返回当前节点的索引值 $heap->key(); // valid() // 判断堆中还是否有其他节点 $heap->valid(); // rewind() // 返回首节点,在堆中是空操作。因为堆是二叉树,rewind始终会在当前位置而不移动 $heap->rewind(); // current() // 获得当前节点 $heap->current(); // next() // 指针移向下一个节点 $heap->next(); // extract() // 从堆的顶部根节点开始,从左到右,抛出一个节点 $heap->extract(); // top() // 获得堆的顶节点 $heap->top(); // recoverFromCorruption // 从崩溃的区域中恢复,并且可以进行其他操作 $heap->recoverFromCorruption();