PHP如何使用SplDoublyLinkedList bottom()函数?

2021年3月28日12:22:23 发表评论 719 次浏览

SplDoublyLinkedList::bottom()函数是PHP中的一个内置函数, 用于从双向链表的开头查看node的值。

语法如下:

mixed SplDoublyLinkedList::bottom( void )

参数:它不接受任何参数。

返回值:它返回双向链表中第一个节点的值。

下面的程序说明了SplDoublyLinkedList :: bottom()PHP中的功能:

程序1:

<?php 
  
// Declare an empty SplDoublyLinkedList
$list = new \SplDoublyLinkedList;
  
// Use SplDoublyLinkedList::push() function to 
// add elements to the SplDoublyLinkedList
$list ->push(1);
$list ->push(2);
$list ->push(3);
$list ->push(8);
$list ->push(5);
  
// Use bottom() function
$val = $list ->bottom();
  
// Display result
print_r( $val ); 
  
?>

输出如下:

1

程式2:

<?php 
  
// Declare an empty SplDoublyLinkedList
$list = new \SplDoublyLinkedList;
  
// Use SplDoublyLinkedList::add() function to 
// add elements to the SplDoublyLinkedList
$list ->add(0, 30);
$list ->add(1, 20);
$list ->add(2, 30);
$list ->add(3, "Geeks" );
$list ->add(4, 'G' );
  
// Use bottom() function
$val = $list ->bottom();
  
// Display result
print_r( $val ); 
  
?>

输出如下:

30

参考: https://www.php.net/manual/en/spldoublylinkedlist.bottom.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: