语法如下:
mixed public DsPriorityQueue::pop ( void )
参数:该函数不接受任何参数。
返回值:此函数返回Queue顶部的现值。函数的返回类型是混合的, 并且取决于存储在队列中的值的类型。
例外注意:如果Queue为空, 则此函数引发UnderflowException。
下面的程序说明了DsQueue::pop()PHP中的功能:
程序1:
<?php // Declare new Queue $q = new DsQueue(); // Add elements to the Queue $q ->push( "One" ); $q ->push( "Two" ); $q ->push( "Three" ); echo "Initial Queue is: n" ; print_r( $q ); // Pop an element echo "nPopped element is: " ; print_r( $q ->pop()); echo "nnFinal Queue is: n" ; print_r( $q ); ?>
输出如下:
Initial Queue is: DsQueue Object ( [0] => One [1] => Two [2] => Three ) Popped element is: One Final Queue is: DsQueue Object ( [0] => Two [1] => Three )
程式2:
<?php // Declare new Queue $q = new DsQueue(); // Add elements to the Queue $q ->push( "Geeks" ); $q ->push( "for" ); $q ->push( "Geeks" ); echo "Initial Queue is: n" ; print_r( $q ); // Pop an element echo "nPopped element is: " ; print_r( $q ->pop()); echo "nnFinal Queue is: n" ; print_r( $q ); ?>
输出如下:
Initial Queue is: DsQueue Object ( [0] => Geeks [1] => for [2] => Geeks ) Popped element is: Geeks Final Queue is: DsQueue Object ( [0] => for [1] => Geeks )
推荐学习:php视频教程