Skip to content

Instantly share code, notes, and snippets.

@christianchristensen
Created August 23, 2010 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianchristensen/544478 to your computer and use it in GitHub Desktop.
Save christianchristensen/544478 to your computer and use it in GitHub Desktop.
<?php
class MinSplPriorityQueue extends SplPriorityQueue
{
public function compare($priority1, $priority2)
{
if ($priority1 === $priority2) return 0;
return $priority1 > $priority2 ? -1 : 1;
}
}
$objPQ = new MinSplPriorityQueue();
$objPQ->insert('A',3);
$objPQ->insert('B',6);
$objPQ->insert('C',1);
$objPQ->insert('D',2);
echo "COUNT->".$objPQ->count()."<BR>";
//mode of extraction
$objPQ->setExtractFlags(MinSplPriorityQueue::EXTR_BOTH);
//Go to TOP
$objPQ->top();
while($objPQ->valid()){
print_r($objPQ->current());
// echo "<BR>";
$objPQ->next();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment