zoukankan      html  css  js  c++  java
  • php实现队列

    <?php
    //双向队列的实现
    class DoubleEndedQueue{
    public $elements;
    public function __construct(){//析构函数,创建一个数组
    $this->elements = array();
    }
    public function push($element){//array_unshift() 函数在数组开头插入一个或多个元素。
    array_unshift($this->elements , $element);
    }
    public function pop(){
    return array_shift($this->elements);//PHP array_shift() 函数删除数组中的第一个元素_
    }
    public function inject($element){//给数组末尾追加元素,无指定下标,默认为数字
    $this->elements[] = $element;
    }
    public function eject(){
    array_pop($this->elements);//PHP array_pop() 函数删除数组中的最后一个元素
    }
    }
    
    //实例化该类,测试下
    $a=new DoubleEndedQueue();
    
    $a->inject(‘aa’);//给数组末尾追加元素,无指定下标,默认为数字
    $a->inject(‘dd’);
    $a->inject(‘cc’);
    $a->inject(‘dd’);
    $a->push(’111′);//函数在数组开头插入一个或多个元素。
    $a->pop();//PHP array_shift() 函数删除数组中的第一个元素_
    $a->eject();//PHP array_pop() 函数删除数组中的最后一个元素
    print_r($a->elements);
    ?>
  • 相关阅读:
    2017加油
    配置SSH框架的心得
    .net 中select和where的区别
    oracle查询中文数据出现乱码
    three.js 加载 obj模型
    下载别人的3D模型文件
    关闭按钮
    桌面截屏保存成gif形式(软件)
    vue 中引入 three.js
    three.js-地球贴图-TextureLoader
  • 原文地址:https://www.cnblogs.com/huay/p/10363840.html
Copyright © 2011-2022 走看看