栈
class Stack
{
private $size;
private $data;
private $currentSize;
public function __construct($size = 10)
{
$this->size = $size;
$this->data = [];
$this->currentSize = 0;
}
public function push($data)
{
if ($this->currentSize >= $this->size) {
throw new \Exception("the stack is full");
}
array_push($this->data, $data);
$this->currentSize++;
}
public function pop()
{
$data = array_pop($this->data);
$this->currentSize--;
return $data;
}
}