PHP SplPriorityQueue extract() Function
Last Updated :
22 Apr, 2021
The SplPriorityQueue::extract() function is an inbuilt function in PHP which is used to extract a node from top of the heap and sift up.
Syntax:
mixed SplPriorityQueue::extract()
Parameters: This function does not accept any parameter.
Return Value: This function returns the value/priority (or both) of the extracted node depending on the extract flag.
Example:
PHP
<?php
class priorityQueue extends SplPriorityQueue {
public function compare($p1, $p2) {
if ($p1 === $p2) return 0;
return $p1 < $p2 ? -1 : 1;
}
}
$obj = new priorityQueue();
$obj->insert("Geeks",2);
$obj->insert("GFG",1);
$obj->insert("G4G",3);
$obj->insert('G',4);
var_dump($obj->extract());
?>
|
Reference: https://www.php.net/manual/en/splpriorityqueue.extract.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...