Queue Handling Library
<?php
function &queue_initialize() {
$new = array();
return $new;
}
function queue_destroy(&$queue) {
unset($queue);
}
function queue_enqueue(&$queue, $value) {
$queue[] = $value;
}
function queue_dequeue(&$queue) {
return array_shift($queue);
}
function queue_peek(&$queue) {
return $queue[0];
}
function queue_size(&$queue) {
return count($queue);
}
function queue_rotate(&$queue) {
$queue[] = array_shift($queue);
}
$myqueue =& queue_initialize();
queue_enqueue($myqueue, 'Opal');
queue_enqueue($myqueue, 'Dolphin');
queue_enqueue($myqueue, 'Pelican');
echo '<p>Queue size is: ', queue_size($myqueue), '</p>';
echo '<p>Front of the queue is: ', queue_peek($myqueue), '</p>';
queue_rotate($myqueue);
echo '<p>Removed the element at the front of the queue: ', queue_dequeue($myqueue), '</p>';
queue_destroy($myqueue);
?>
Related examples in the same category