This article mainly introduced the PHP data structure queue (SPLQUEUE) and the priority queue (Splpriorityqueue) Simple use instance, needs the friend to be possible to refer to under
The data structure of queues is simpler, as in the line of our lives, its characteristics are FIFO.
PHP SPL Splqueue class is to implement the queue operation, and the same as the stack, it can inherit the double linked list (spldoublylinkedlist) easily implemented.
The Splqueue class summary is as follows:
The splqueue is simple to use as follows:
The code is as follows:
$queue = new Splqueue ();
/**
* Visible queue and double linked list is the difference is iteratormode changed, the stack of Iteratormode can only be:
* (1) spldoublylinkedlist::it_mode_fifo | Spldoublylinkedlist::it_mode_keep (default value, after iteration data save)
* (2) Spldoublylinkedlist::it_mode_fifo | Spldoublylinkedlist::it_mode_delete (Data deletion after iteration)
*/
$queue->setiteratormode (Spldoublylinkedlist::it_mode_fifo | Spldoublylinkedlist::it_mode_delete);
Splqueue::enqueue () is actually spldoublylinkedlist::p Ush ()
$queue->enqueue (' a ');
$queue->enqueue (' B ');
$queue->enqueue (' C ');
Splqueue::d equeue () is actually spldoublylinkedlist::shift ()
Print_r ($queue->dequeue ());
foreach ($queue as $item) {
Echo $item. Php_eol;
}
Print_r ($queue);
and the priority queue Splpriorityqueue is implemented based on the heap (after the article).
The Splpriorityqueue class summary is as follows:
Splpriorityqueue Simple to use:
?