Ds \ PriorityQueue :: pop()PHP中的函数用于删除并返回出现在PriorityQueue顶部的值。换句话说, 它返回PriorityQueue中具有最高优先级的值并将其删除。
语法如下:
mixed public Ds\PriorityQueue::pop ( void )
参数:该函数不接受任何参数。
返回值:此函数返回此PriorityQueue中具有最高优先级的值, 并将其删除。函数的返回类型是混合的, 并且取决于存储在PriorityQueue中的值的类型。
例外:如果PriorityQueue为空, 则此函数将引发UnderflowException。
下面的程序说明了Ds \ PriorityQueue :: pop()PHP中的功能:
程序1:
<?php
// Declare new PriorityQueue
$pq = new \Ds\PriorityQueue();
// Add elements to the PriorityQueue
$pq ->push( "One" , 1);
$pq ->push( "Two" , 2);
$pq ->push( "Three" , 3);
echo "Initial PriorityQueue is: \n" ;
print_r( $pq );
// Pop an element
echo "\nPopped element is: " ;
print_r( $pq ->pop());
echo "\n\nFinal PriorityQueue is: \n" ;
print_r( $pq );
?>
输出如下:
Initial PriorityQueue is:
Ds\PriorityQueue Object
(
[0] => Three
[1] => Two
[2] => One
)
Popped element is: Three
Final PriorityQueue is:
Ds\PriorityQueue Object
(
[0] => Two
[1] => One
)
程式2:
<?php
// Declare new PriorityQueue
$pq = new \Ds\PriorityQueue();
// Add elements to the PriorityQueue
$pq ->push( "One" , 1);
$pq ->push( "Two" , 3);
$pq ->push( "Three" , 2);
echo "Initial PriorityQueue is: \n" ;
print_r( $pq );
// Pop an element
echo "\nPopped element is: " ;
print_r( $pq ->pop());
echo "\n\nFinal PriorityQueue is: \n" ;
print_r( $pq );
?>
输出如下:
Initial PriorityQueue is:
Ds\PriorityQueue Object
(
[0] => Two
[1] => Three
[2] => One
)
Popped element is: Two
Final PriorityQueue is:
Ds\PriorityQueue Object
(
[0] => Three
[1] => One
)
参考: http://php.net/manual/en/ds-priorityqueue.pop.php