php简单的双向队列


class DoubleQueue{

    private $_queue=array();
   
    public function __construct()
    {
    }
   
    /**
     * 得到数组的总大小
     */
    public function count()
    {
        return count($this->_queue);
    }
   
    /**
     * 将一个单元压入数组尾部
     */
    public function queuePush($data)
    {
        return array_push($this->_queue,$data);
    }
   
    /**
     *将一个单元压入数组开头
     */
    public function queueUnshift($data)
    {
        return array_unshift($this->_queue,$data);
    }
   
    /**
     * 从数组最后一个移出
     */
    public function queuePop()
    {
        if($this->count()<=0){
            return false;
        }
        return array_pop($this->_queue);
    }
   
    /**
     * 将数组中的第一个单元移出
     */
    public function queueShift()
    {
        if($this->count()<=0){
            return false;
        }
        return array_shift($this->_queue);
    }
   
    /**
     * 清空队列
     */
    public function queueEmpty()
    {
        return unserialize($this->_queue);
    }
   
    /**
     * 查找某个值是否在队列中
     * @param 要查找的值
     */
    public function queueExist($data)
    {
        if( !is_array($data) && $this->count() >= 1 ) {
            return in_array($data,$this->_queue);
        } else {
            return false;
        }
    }
   
    /**
     * 得到某个索引的value
     * @param $index  索引
     */
    public function getIndexQueue($index)
    {
        if( is_numeric($index) &&  $this->count() >= 1) {
            return $this->_queue[$index];
        } else {
            return false;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值