PHP DoublyLinkedList example

/*

* 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();

/**
Our Linked List:SplDoublyLinkedList Object ( [flags:SplDoublyLinkedList:private] => 0 [dllist:SplDoublyLinkedList:private] => Array ( [0] => 10 [1] => 2 [2] => 3 ) )
Pick the node from beginning of doubly linked list10
*/

Leave a Reply

You must be logged in to post a comment.