/**
* Data structures and algorithms (implemented in PHP)-Queue ).
*
* @ Author creative programming (TOPPHP. ORG)
* @ Copyright Copyright (c) 2013 creative programming (TOPPHP. ORG) All Rights Reserved
* @license http://www.opensource.org/licenses/mit-license.php MIT LICENSE
* @version 1.0.0 - Build20130607
*/
class Queue {
/**
* Queue.
*
* @var array
*/
private $queue ;
/**
* Queue length.
*
* @var integer
*/
private $size ;
/**
* Constructor-Initialize data.
*/
public function __construct() {
$this ->queue = array ();
$this ->size = 0;
}
/**
* Queue operations.
*
* @ Param mixed $ data queue data.
* @ Return object returns the object itself.
*/
public function enqueue( $data ) {
$this ->queue[ $this ->size++] = $data ;
return $this ;
}
/**
* Team-out operations.
*
* @ Return mixed: FALSE is returned when the queue is empty. Otherwise, the Header element of the queue is returned.
*/
public function dequeue() {
if (! $this ->isEmpty()) {
-- $this ->size;
$front = array_splice ( $this ->queue, 0, 1);
return $front [0];
}
return FALSE;
}
/**
* Get the queue.
*
* @ Return array returns the entire queue.
*/
public function getQueue() {
return $this ->queue;
}
/**
* Obtain the element of the team header.
*
* @ Return mixed: FALSE is returned when the queue is empty. Otherwise, the Header element of the queue is returned.
*/
public function getFront() {
if (! $this ->isEmpty()) {
return $this ->queue[0];
}
return FALSE;
}
/**
* Get the queue length.
*
* @ Return integer returns the length of the queue.
*/
public function getSize() {
return $this ->size;
}
/**
* Check whether the queue is empty.
*
* @ Return boolean if the queue is empty, TRUE is returned; otherwise, FALSE is returned.
*/
public function isEmpty() {
return 0 === $this ->size;
}
}
?>
|