/** * 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; } }
/** * @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; }
/** * @return mixed */ public function peek() { return $this->top->getData(); }