PHP implementation of the chain queue structure example, php chain queue example
This example describes the chained queue structure implemented by PHP. We will share this with you for your reference. The details are as follows:
<? Phpheader ("Content-Type: text/html; charset = UTF-8");/*** chained queue */class node {public $ nickname; public $ next ;} class queue {public $ front; // Head public $ tail; // tail public $ maxSize; // CAPACITY public $ next; // pointer public $ len = 0; // length public function _ construct ($ size) {$ this-> init ($ size);} public function init ($ size) {$ this-> front = $ this; $ this-> tail = $ this; $ this-> maxSize = $ size;} // The public function inQ ($ Nickname) {$ node = new node (); $ node-> nickname = $ nickname; if ($ this-> len = $ this-> maxSize) {echo 'team full </br>';} else {$ this-> tail = $ node; $ this-> tail-> next = $ node; $ this-> len ++; echo $ node-> nickname. 'queued successfully </br> '; }}// the public function outQ () {if ($ this-> len = 0) {echo 'Team blank </br> ';} else {$ p = $ this-> front-> next; $ this-> front-> next = $ p-> next; $ this-> len --; echo $ p-> nickname. 'Team-out successful </br> ';} // Print the public function show () {for ($ I = $ this-> len; $ I> 0; $ I --) {$ this-> outQ ();}}} echo "****************************** </br> "; $ q = new queue (5); $ q-> inQ (' yunlong'); $ q-> inQ ('huafans '); $ q-> inQ ('green-faced bean'); $ q-> inQ ('walker '); $ q-> inQ ('yu Qilin '); $ q-> inQ ('sleep ycle '); echo "******************************* </br> "; $ q-> outQ (); $ q-> inQ ('zombie bean'); $ q-> inQ ('ghost being'); $ q-> inQ ('ghost beak '); $ q-> outQ ();?>
Running result: