コード例 #1
0
ファイル: Queue.php プロジェクト: bluesnowman/Chimera
 /**
  * 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);
 }
コード例 #2
0
ファイル: Stack.php プロジェクト: bluesnowman/Chimera
 /**
  * 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;
 }
コード例 #3
0
ファイル: Deque.php プロジェクト: bluesnowman/Chimera
 /**
  * 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;
 }