From afd6ec6e92707f425b0aa6bceaaa23bd91c93a2f Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Sun, 19 Nov 2023 10:52:11 +0100 Subject: [PATCH] Add alias methods to StrictQueue and StrictStack --- src/DataStructures/StrictQueue.php | 26 ++++++++++++++++++++++++++ src/DataStructures/StrictStack.php | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/DataStructures/StrictQueue.php b/src/DataStructures/StrictQueue.php index 322c2b9..e07b431 100644 --- a/src/DataStructures/StrictQueue.php +++ b/src/DataStructures/StrictQueue.php @@ -37,6 +37,32 @@ use RuntimeException; */ class StrictQueue extends StrictList { + /** + * Dequeue an item from the queue. + * @see \SplQueue::dequeue() + * + * @return mixed The dequeued item + */ + public function dequeue(): mixed + { + return parent::shift(); + } + + /** + * Add an item to the queue. + * @see \SplQueue::enqueue() + * + * @param mixed $item The item to enqueue + * + * @return void + * + * @throws \InvalidArgumentException + */ + public function enqueue(mixed $item): void + { + parent::push($item); + } + /** * Set the mode of iteration. * @see \SplDoublyLinkedList::setIteratorMode() diff --git a/src/DataStructures/StrictStack.php b/src/DataStructures/StrictStack.php index e034de5..c46130f 100644 --- a/src/DataStructures/StrictStack.php +++ b/src/DataStructures/StrictStack.php @@ -37,6 +37,30 @@ use RuntimeException; */ class StrictStack extends StrictList { + /** + * Add an item to the stack. + * + * @param mixed $item The item to stack + * + * @return void + * + * @throws \InvalidArgumentException + */ + public function stack(mixed $item): void + { + parent::push($item); + } + + /** + * Unstack an item from the stack. + * + * @return mixed The unstacked item + */ + public function unstack(): mixed + { + return parent::pop(); + } + /** * Set the mode of iteration. * @see \SplDoublyLinkedList::setIteratorMode()