Beispiel #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;
     }
 }
Beispiel #2
0
 /**
  * @param $value
  * @return bool
  */
 public function push($value)
 {
     $newNode = new LinkedListNode($value);
     if ($this->isEmpty()) {
         $this->top = $newNode;
         $this->bottom = $newNode;
     } else {
         $oldTop = $this->top;
         $this->top = $newNode;
         $newNode->setNext($oldTop);
     }
 }