You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
558 B
39 lines
558 B
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Util;
|
|
|
|
class Stack
|
|
{
|
|
protected $stack;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->stack = [];
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return sizeof($this->stack);
|
|
}
|
|
|
|
public function get(): array
|
|
{
|
|
return $this->stack;
|
|
}
|
|
|
|
public function pop(int $offset = 0)
|
|
{
|
|
if (sizeof($this->stack) < $offset + 1)
|
|
{
|
|
throw new \Exception('Stack underflow!');
|
|
}
|
|
return array_splice($this->stack, -1 * ($offset + 1), 1)[0];
|
|
}
|
|
|
|
public function push($value): void
|
|
{
|
|
array_push($this->stack, $value);
|
|
}
|
|
}
|
|
|