队列



class Queue
{
    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 queue is full");
        }
        array_push($this->data, $data);
        $this->currentSize++;
    }

    public function pop()
    {
        $data = array_shift($this->data);
        $this->currentSize--;
        return $data;
    }
}

results matching ""

    No results matching ""