Last active
December 13, 2015 20:29
-
-
Save rifki/4970629 to your computer and use it in GitHub Desktop.
SPLStack & SplQueue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
) | |
) | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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