Created
July 1, 2010 10:05
-
-
Save TechZi/459794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Queue { | |
private $_queueArr; | |
private $_front; | |
private $_rear; | |
private $_queueSize = 10; | |
public function __construct() { | |
$this->_queueArr = array(); | |
$this->_front = -1; | |
$this->_rear = -1; | |
} | |
public function isEmpty() { | |
return ($this->_front == $this->_rear); | |
} | |
public function isFull() { | |
return (count($this->_rear) == $this->_queueSize); | |
} | |
public function enqueue($num) { | |
if ($this->isFull()) { | |
echo "the queue is full \n"; | |
return; | |
} | |
if ($this->isEmpty()) { | |
++$this->_front; | |
} | |
if (++$this->_rear == $this->_queueSize) { | |
$this->_rear = 0; | |
} | |
$this->_queueArr[$this->_rear] = $num; | |
} | |
public function dequeue() { | |
if ($this->isEmpty()) { | |
echo 'the queue is empty'; | |
return ; | |
} | |
$num = $this->_queueArr[$this->_front]; | |
if (++$this->_front == $this->_queueSize) { | |
$this->_front = 0; | |
} | |
return $num; | |
} | |
public function display() { | |
if ($this->isEmpty()) { | |
echo 'the queue is empty'; | |
return ; | |
} | |
while ($this->isEmpty()) { | |
} | |
} | |
} | |
$queue = new Queue(); | |
$queue->enqueue(1); | |
$queue->enqueue(2); | |
$queue->enqueue(3); | |
$queue->enqueue(4); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment