<?phpclass queueop{/* * Team Tail * Return: Number of elements in queue after processing */Public function Tailenquque ($arr, $val) {Retu RN Array_push ($arr, $val);} /* * End of Team * return: The last value, if the array is empty or not an array, returns NULL * Comment: For two-way queue only */Public function Taildequeue ($arr) { Return Array_pop ($arr); }/* * Team First queue * Return: Number of elements queued after processing * Comment: For two-way queue only */Public function headenqueue ($arr, $val) {RET Urn Array_unshift ($arr, $var); }/* Team first OUT team * return: The removed value, if the parameter is not an array or an array is empty, returns NULL */Public Function Headdequeue () {return Array_shift ($ ARR); }/* Queue Length * return: Returns the length of the queue (number of elements) */Public Function queuelength ($arr) {return count ($arr); }/* * Get team first element * return: The value of the first element, or False if the queue is empty */Public Function Queuehead ($arr) {return Reset ( $arr); }/* Gets the tail element * return: The value of the last element and returns False if the queue is empty */Public Function Queuetail ($arr) {return End ($a RR); }/* * Empty queue * RetuRN: no return value */Public Function Clearqueue ($arr) {unset ($arr); }}<?phpclass phpstack{Public $top =-1; Public $size = 5; Public $stack = Array (); Public function __construct ($size) {$this->size = $size; Public function push ($item) {if ($this->isfull ()) {return; } $this->top++; $this->stack[$this->top]= $item; Public Function Pop () {if ($this->isempty ()) {return; } $ret = $this->stack[$this->top]; $this->top--; return $ret; Public Function Isfull () {if (($this->top+1) >= $this->size) {echo ' The stack is full! '; return true; }} Public Function IsEmpty () {if ($this->top==-1) {echo ' The stack is empty '; return true; }} public Function Show () {for ($i = $this->top; $i >-1; $i-) {echo $i. Element is: ". $this->stack[$i]. " <br/> "; }}}?>
PHP implementation Stack and queue