当前位置:Gxlcms > PHP教程 > PHP实现双向队列算法代码

PHP实现双向队列算法代码

时间:2021-07-01 10:21:17 帮助过:16人阅读

PHP实现双向队列算法代码

PHP如何实现双向队列

queue,$node);
		$this->countqueue();
	}
	public function frontRemove(){
		$node = array_shift($this->queue);
		$this->countqueue();
		return $node;
	}
	  
	public function rearAdd($node){
		array_push($this->queue,$node);
		$this->countqueue();
	}
	 
	public function rearRemove(){
		$node = array_pop($this->queue);
		$this->countqueue();
		return $node;
	}
	 
	public function countqueue(){
		$this->length = count($this->queue);    
	}
}
// 测试用,面试答题可不写以下部分
$fruit = new deque();
echo $fruit -> length;
$fruit -> frontAdd("Apple");
$fruit -> rearAdd("Watermelon");
print_r($fruit);
?>

人气教程排行