PHP uses arrays to implement queues. We only need to use the rray_push () and array_pop () system functions. Let's take a look at them. I hope the example will be helpful to you. PHP uses arrays to implement queues. We only need to use the rray_push () and array_pop () system functions. Let's take a look at them. I hope the example will be helpful to you.
Script ec (2); script
Example
| The Code is as follows: |
|
|
/**
* @ Php simulated queue
*/
Class Queue
{
Private $ myQueue; // queue container
Private $ size; // Queue Length
Public function _ construct ()
{
$ This-> myQueue = array ();
$ This-> size = 0;
}
/**
* @ Inbound stack operation
*/
Public function putQueue ($ data)
{
$ This-> myQueue [$ this-> size ++] = $ data;
Return $ this;
}
/**
* @ Output Stack
*/
Public function getQueue ()
{
If (! $ This-> isEmpty ())
{
$ Front = array_splice ($ this-> myQueue, 0, 1 );
$ This-> size --;
Return $ front [0];
}
Return false;
}
/**
* @ Get all message queues
*/
Public function allQueue ()
{
Return $ this-> myQueue;
}
/**
* @ Get queue statement
*/
Public function frontQueue ()
{
If (! $ This-> isEmpty ())
{
Return $ this-> myQueue [0];
}
Return false;
}
/**
* @ Return Queue Length
*/
Public function getSize ()
{
Return $ this-> size;
}
Public function isEmpty ()
{
Return 0 ===$ this-> size;
}
}
?> |