Main theme: The function of the array
Array_pop Array_push
the Array_pop array_pop () function deletes the last element in the array. Delete the trailing Array_push the Array_push () function adds one or more elements (into the stack) to the end of the array of the first parameter, and then returns the length of the new array. the function equals multiple calls $array [] = $value. The tail plugs into a
Array_unshift Array_shift
The Array_shift () function deletes the first element in the array and returns the value of the deleted element. Delete Header the first array_unshift () function is used to insert a new element into an array. The value of the new array is inserted at the beginning of the array. Insert Head First
Reset End
The Reset reset () function points the internal pointer to the first element in the array and outputs it. The End End () function points the array's internal pointer to the last element and returns the value of the element, if successful.
Implementation code:
<?phpclass Deque {public $queue = array (); /** (tail) Queue **/public Function addlast ($value) {return Array_push ($this->queue, $value); }/** (tail) out of Team **/public Function Removelast () {return Array_pop ($this->queue); }/** (head) Queue **/public Function AddFirst ($value) {return Array_unshift ($this->queue, $value); }/** (head) out of the team **/public Function Removefirst () {return array_shift ($this->queue); }/** Empty Queue **/public Function Makeempty () {unset ($this->queue); }/** Gets the column header **/public function GetFirst () {return reset ($this->queue); } /** Gets the column footer **/public function GetLast () {return end ($this->queue); } /** gets the length **/public function GetLength () {return count ($this->queue); } }