| Total Complexity | 10 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class ImplementQueueUsingStacks |
||
| 8 | { |
||
| 9 | private array $cache = []; |
||
| 10 | private array $stack = []; |
||
| 11 | private ?int $front; |
||
| 12 | |||
| 13 | public function push(int $value): void |
||
| 14 | { |
||
| 15 | if (empty($this->stack)) { |
||
| 16 | $this->front = $value; |
||
| 17 | } |
||
| 18 | while (!empty($this->stack)) { |
||
| 19 | $this->cache[] = array_shift($this->stack); |
||
| 20 | } |
||
| 21 | $this->cache[] = $value; |
||
| 22 | while (!empty($this->cache)) { |
||
| 23 | $this->stack[] = array_shift($this->cache); |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | public function pop(): ?int |
||
| 35 | } |
||
| 36 | |||
| 37 | public function peek(): ?int |
||
| 44 | } |
||
| 45 | |||
| 46 | public function empty(): bool |
||
| 49 | } |
||
| 50 | } |
||
| 51 |