CKTIS / PHP
SplDoublyLinkedList
Maintain a list with insertion and removal at both ends. push and pop operate at the tail; unshift and shift operate at the head. bottom and top inspect the ends without removing them.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
new SplDoublyLinkedList()Maintain a list with insertion and removal at both ends. push and pop operate at the tail; unshift and shift operate at the head. bottom and top inspect the ends without removing them. Removing from an empty list raises RuntimeException.
$list=new SplDoublyLinkedList(); $list->push("B"); $list->unshift("A"); $list->push("C");
$seen=[$list->bottom(),$list->top(),$list->shift(),$list->pop(),$list->count()]; echo json_encode($seen);
["A","C","A","C",1]
Examples
<?php
$list=new SplDoublyLinkedList(); $list->push("B"); $list->unshift("A"); $list->push("C");
$seen=[$list->bottom(),$list->top(),$list->shift(),$list->pop(),$list->count()]; echo json_encode($seen);
Result
["A","C","A","C",1]