PHP使用数组实现队列类程序
例子
<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;
}
}
?>
您可能感兴趣的文章: