Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
3 / 6 |
CRAP | |
76.32% |
29 / 38 |
Queue | |
0.00% |
0 / 1 |
|
50.00% |
3 / 6 |
13.91 | |
76.32% |
29 / 38 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
enqueue | |
100.00% |
1 / 1 |
2 | |
100.00% |
10 / 10 |
|||
dequeue | |
0.00% |
0 / 1 |
4.01 | |
92.86% |
13 / 14 |
|||
listAll | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
|||
peek | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
isEmpty | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
<?php namespace Mtkocak\DataStructures; | |
class Queue | |
{ | |
public $head; | |
public $tail; | |
function __construct(){ | |
$this->head = NULL; | |
$this->tail = NULL; | |
} | |
public function enqueue($value){ | |
$newNode = new SingleLinkedListNode($value); | |
if($this->isEmpty()) | |
{ | |
$this->head = $newNode; | |
$this->tail = $newNode; | |
}else{ | |
$currentTail = $this->tail; | |
$newNode->next($currentTail); | |
$this->tail = $newNode; | |
} | |
} | |
public function dequeue(){ | |
$current = $this->tail; | |
if($current == $this->head){ | |
$this->tail = NULL; | |
$this->head = NULL; | |
return $current->get(); | |
} | |
while($current){ | |
if($current->next() == $this->head){ | |
$nodeToDelete = $this->head; | |
$this->head = $current; | |
$current->next = NULL; | |
return $nodeToDelete->get(); | |
} | |
$current = $current->next(); | |
} | |
return false; | |
} | |
public function listAll(){ | |
$current = $this->tail; | |
$listToReturn = []; | |
while($current){ | |
array_push($listToReturn, $current->get()->get()); | |
$current = $current->next(); | |
} | |
return $listToReturn; | |
} | |
public function peek(){ | |
return $this->head->get(); | |
} | |
public function isEmpty(){ | |
if($this->head == NULL){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
} |