• 用php实现一个双向队列


    1 <?php
    2 class deque
    3 {
    4 public $queue = array();
    5 public $length = 0;
    6
    7 public function frontAdd($node){
    8 array_unshift($this->queue,$node);
    9 $this->countqueue();
    10 }
    11
    12 public function frontRemove(){
    13 $node = array_shift($this->queue);
    14 $this->countqueue();
    15 return $node;
    16 }
    17
    18 public function rearAdd($node){
    19 array_push($this->queue,$node);
    20 $this->countqueue();
    21 }
    22
    23 public function rearRemove(){
    24 $node = array_pop($this->queue);
    25 $this->countqueue();
    26 return $node;
    27 }
    28
    29 public function countqueue(){
    30 $this->length = count($this->queue);
    31 }
    32 }
    33  ?>

    这道题从难度上讲其实不是很难,它主要考察了phper以下几个方面的技能:
    1. 当然是双向队列的定义,这个就不多做解释了。
    2. 考察对函数是否熟悉。
    3. 考察OOP编程。
    4. 考察程序员的代码规范和编程习惯。

    aliyun活动 https://www.aliyun.com/acts/limit-buy?userCode=re2o7acl
  • 相关阅读:
    tcpdump高级过滤
    Flask简单学习
    nginx+keepalived高可用web负载均衡
    Golang基础(5):Go语言反射规则
    Golang基础(4):Go结构体
    分布式SESSION一致性
    JSON WEB TOKEN (JWT)
    Table布局
    GRID布局
    三种方式实现轮播图功能
  • 原文地址:https://www.cnblogs.com/wangbin/p/1959550.html
Copyright © 2020-2023  润新知