教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP使用数组实现队列类程序

PHP使用数组实现队列类程序

发布时间:2016-10-19   编辑:jiaochengji.com
教程集为您提供PHP使用数组实现队列类程序等资源,欢迎您收藏本站,我们将为您提供最新的PHP使用数组实现队列类程序资源
PHP使用数组实现队列我们只要用到 rray_push()和array_pop()两个系统函数来完成了,下面一起来看看吧,希望例子对各位有帮助。

例子

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5141')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5141>

<?php
/**
*@php模拟  队列
*/
class Queue
{
 private $myQueue;  //队列容器
 private $size ;     //队列的长度
 public function __construct()
 {
  $this->myQueue=array();
  $this->size=0;
 }

 /**
 *@入栈操作
 */
 public function putQueue($data)
 {
  $this->myQueue[$this->size ]=$data;
  return $this;
 }
 /**
 *@出栈
 */
 public function getQueue()
 {
  if(!$this->isEmpty())
  {
                    $front=array_splice($this->myQueue,0,1);
                    $this->size--;
      return $front[0];
  }
  return false;
 }
 /**
 *@ 获取全部的消息队列
 */
 public function allQueue()
 {
  return $this->myQueue;
 }
 /**
 *@ 获取队列的表态
 */
 public function frontQueue()
 {
  if(!$this->isEmpty())
  {
   return $this->myQueue[0];
  }
  return false;
 }
 /**
 *@ 返回队列的长度
 */
 public function getSize()
 {
  return $this->size;
 }

   public function isEmpty()
   {
     return 0===$this->size;
   }
}
?>

您可能感兴趣的文章:

[关闭]
~ ~