/** * This method dequeues the element at the head of the queue. * * @access public * @throws Throwable\EmptyCollection\Exception indicates no element could be dequeued * @return mixed the element that is dequeued */ public function dequeue() { if ($this->list->isEmpty()) { throw new Throwable\EmptyCollection\Exception('Unable to dequeue an element from the queue. Collection contains no elements.'); } $value = $this->list->getValue(0); $this->list->removeIndex(0); return $value; }
/** * This method pops the top element off the stack. * * @access public * @return mixed the element at the top of the stack * @throws Throwable\EmptyCollection\Exception indicates that no more elements are * on the stack */ public function pop() { if ($this->list->isEmpty()) { throw new Throwable\EmptyCollection\Exception('Unable to pop an element off the stack. Collection contains no elements.'); } $index = $this->list->count() - 1; $value = $this->list->getValue($index); $this->list->removeIndex($index); return $value; }
/** * This method pops off the element at the back of the deque. * * @access public * @return mixed the element from the back of the deque * @throws Throwable\EmptyCollection\Exception indicates that no more elements are * on the deque */ public function popBack() { if ($this->isEmpty()) { throw new Throwable\EmptyCollection\Exception('Trying to pop element from empty deque'); } $index = $this->list->count() - 1; $value = $this->list->getValue($index); $this->list->removeIndex($index); return $value; }