php教程

SplDoublyLinkedList::bottom

(PHP 5 >= 5.3.0, PHP 7)

SplDoublyLinkedList::bottomPeeks at the node from the beginning of the doubly linked list

说明

public SplDoublyLinkedList::bottom ( void ) : mixed

参数

此函数没有参数。

返回值

The value of the first node.

错误/异常

Throws RuntimeException when the data-structure is empty.

User Contributed Notes

lincoln dot du dot j at gmail dot com 11-Jul-2017 05:30
$a = new SplDoublyLinkedList;
$arr=[1,2,3,4,5,6,7,8,9];

for($i=0;$i<count($arr);$i++){
    $a->add($i,$arr[$i]);
}

echo "SplDoublyLinkedList array last/top value " .  $a->top() ." \n";
echo "SplDoublyLinkedList array first/top value " . $a->bottom() . " \n\n";

print_r($a);

//Another Example
$spl = new SplDoublyLinkedList;

$spl->push(11);
$spl->push(2);
$spl->push(3);
$spl->push(8);
$spl->push(5);

//array last value
echo $spl->top();
echo PHP_EOL;
//Array first value
echo $spl->bottom();
echo PHP_EOL;

print_r($spl);
tstirrat at gmail dot com 27-Apr-2014 10:27
A note on top() and bottom():

Picture the doubly-linked list (or queue) in the same way that you would a stack.

Say you started with an empty queue, and added five values:

$myList = new SplDoublyLinkedList

$mylist->push(1)
$mylist->push(2)
$mylist->push(3)
$mylist->push(4)
$mylist->push(5)

$mylist->top()
-> 5

$mylist->bottom()
-> 1
rakesh dot mishra at gmail dot com 26-Jan-2011 10:39
<?php

/*
 * Examples of DoublyLinkedList
 */

$obj = new SplDoublyLinkedList();

// Check wither linked list is empty
if ($obj->isEmpty())
{
    echo
"Adding nodes to Linked List<br>";
   
$obj->push(2);
   
$obj->push(3);
   
    echo
"Adding the node at beginning of doubly linked list <br>";
   
$obj->unshift(10);
}

echo
"<br>Our Linked List:";
print_r($obj);

echo
"<br>Pick the node from beginning of doubly linked list";
echo
$obj->bottom();

?>

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788