用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. 考察程序员的代码规范和编程习惯。

转载于:https://www.cnblogs.com/wangbin/archive/2011/02/21/1959550.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值