/** * This method returns the element at the head of the queue, but does not remove it. * * @access public * @throws Throwable\EmptyCollection\Exception indicates no element could be dequeued * @return mixed the element at the head of the queue */ public function peek() { if ($this->list->isEmpty()) { throw new Throwable\EmptyCollection\Exception('Unable to peek at next element in the queue. Collection contains no elements.'); } return $this->list->getValue(0); }
/** * 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 a boolean value representing whether the queue is empty. * * @access public * @return boolean whether the queue is empty */ public function isEmpty() { return $this->list->isEmpty(); }