/** * 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; }
/** * 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 returns the count of elements in the queue. * * @access public * @return integer the count of elements in the queue */ public function count() { return $this->list->count(); }