PHP SplPriorityQueue next() Function
The SplPriorityQueue::next() function is an inbuilt function in PHP that is used to extract the top node from the queue.
Syntax:
void SplPriorityQueue::next()
Parameters: This function does not accept any parameter.
Return Value: This function does not return any value.
Example:
PHP
<?php // Declare a class class priorityQueue extends SplPriorityQueue { // Compare function to compare priority // queue elements public function compare( $p1 , $p2 ) { if ( $p1 === $p2 ) return 0; return $p1 < $p2 ? -1 : 1; } } // Create an object of priority queue $obj = new priorityQueue(); // Insert elements into the queue $obj ->insert( "Beginner" ,2); $obj ->insert( "GFG" ,1); $obj ->insert( "G4G" ,3); $obj ->insert( 'G' ,4); // Loop to print the priority // queue elements while ( $obj ->valid()){ // Print the current element echo $obj ->current() . " " ; // Move to next element of // priority queue $obj ->next(); } ?> |
Output
G G4G Beginner GFG
Reference: https://www.php.net/manual/en/splpriorityqueue.next.php
Contact Us