Queue Handling Library : array « Data Structure « PHP






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

1.A list of numbers using an array variable
2.Accessing Array Elements
3.Arrays
4.Converting an object to an array will convert properties to elements of the resulting array
5.Create an array
6.Creates an array with keys 0 through 3
7.Creating arrays with array()
8.Creating multidimensional arrays with array()
9.Creating numeric arrays with array()
10.Setting up an associative array is similarly easy
11.Demonstrate the Difference Between the Array '+' Operator and a True Array Union
12.Using the array function to create an array of weekdays
13.Using the array() Function
14.Stack Handling Library