<?php class Heap extends SplMinHeap { public function &compare($a, $b) { return $a; } } $h = new Heap(); $h->insert(0); $h->insert(0); ?> ===DONE===
* Gets the left child's key of a given node */ static function node_child_left($key) { return $key * 2 + 1; } /** * Gets the right child's key of a given node */ static function node_child_right($key) { return $key * 2 + 2; } function toString() { foreach ($this->keys as $key) { echo "[{$key}]"; } echo "<br/>"; } } $heap = new Heap(); for ($i = 0; $i < 10; $i++) { $heap->insert(rand(1, 15)); $heap->toString(); } $heap->toString(); for ($i = 0; $i < 10; $i++) { echo "<strong>" . $heap->extract_min() . "</strong><br/>"; $heap->toString(); }