Exemple #1
0
 /**
  * add an item to the “end” (tail) of the queue
  * @param $value
  */
 public function enqueue($value)
 {
     $newNode = new LinkedListNode($value);
     if ($this->isEmpty()) {
         $this->head = $newNode;
         $this->tail = $newNode;
     } else {
         $currentTail = $this->tail;
         $newNode->setNext($currentTail);
         $this->tail = $newNode;
     }
 }
Exemple #2
0
 /**
  * @return int
  */
 public function count()
 {
     if ($this->count === null) {
         $this->rewind();
         $count = 0;
         while ($this->current) {
             $count++;
             $this->current = $this->current->getNext();
         }
         $this->count = $count;
     }
     return $this->count;
 }
Exemple #3
0
 /**
  * @return mixed
  */
 public function peek()
 {
     return $this->top->getData();
 }