Skip to content

Instantly share code, notes, and snippets.

@rifki
Last active December 13, 2015 20:29
Show Gist options
  • Save rifki/4970629 to your computer and use it in GitHub Desktop.
Save rifki/4970629 to your computer and use it in GitHub Desktop.
SPLStack & SplQueue
<?php
$doublyList = new SplQueue();
if ($doublyList->isEmpty()) {
$doublyList->enqueue('PHP');
$doublyList->enqueue('Java');
$doublyList->enqueue('Python');
$doublyList->enqueue('Ruby');
}
print_r($doublyList);
if (! $doublyList->offsetExists(4)) {
$doublyList->enqueue('JS');
}
print_r($doublyList);
// dequeue
$doublyList->dequeue();
print_r($doublyList);
/** output:
SplQueue Object
(
[flags:SplDoublyLinkedList:private] => 4
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => PHP
[1] => Java
[2] => Python
[3] => Ruby
)
)
SplQueue Object
(
[flags:SplDoublyLinkedList:private] => 4
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => PHP
[1] => Java
[2] => Python
[3] => Ruby
[4] => JS
)
)
SplQueue Object
(
[flags:SplDoublyLinkedList:private] => 4
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => Java
[1] => Python
[2] => Ruby
[3] => JS
)
)
**/
<?php
$stack = new SPLStack();
$stack->push('a');
$stack->push('b');
$stack->push('c');
$stack->push('d');
echo $stack->pop();
echo $stack->pop();
// output: dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment