PHP数组 第6章 双向队列 PHP数组 第6章 双向队列

2023-07-28

双向队列

class DEQueue {
    //存储
    protected $_storage = array();
    
    //入头
    public function unshift($element)
    {
        return array_unshift($this->_storage, $element);
    }
    
    //入尾
    public function push($element)
    {
        return array_push($this->_storage, $element);
    }
    
    //出尾
    public function pop()
    {
        return array_pop($this->_storage);
    }
    
    //出头
    public function shift()
    {
        return array_shift($this->_storage);
    }
    
    //长度
    public function length()
    {
        return count($this->_storage);
    }
}

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开微信扫一扫,即可进行扫码打赏哦

阅读 259