How to use php to implement a two-way queue code instance

Source: Internet
Author: User
The function deletes the last element in the array. Delete a function at the end to add one or more elements to the end of the array of the first parameter (in the stack), and then return the length of the new array. Purpose: mainly test the array functions.

Array_pop array_push

The array_pop () function deletes the last element in the array. Delete the array_push () function to add one or more elements to the end of the array of the first parameter (in the stack), and then return the length of the new array. This function is equivalent to calling $ array [] = $ value multiple times. End of plug-in 1

Array_unshift array_shift

The array_shift () function deletes the first element in the array and returns the value of the deleted element. The first array_unshift () function is used to insert new elements into the array. The value of the new array is inserted at the beginning of the array. Insert first

Reset end

The reset () function points the internal pointer to the first element in the array and outputs it. The end () function points the internal pointer of the array to the last element and returns the value (if successful) of the element ).

Implementation code:

 Queue, $ value);}/** (tail) team-OUT **/public function removeLast () {return array_pop ($ this-> queue);}/** (header) queue **/public function addFirst ($ value) {return array_unshift ($ this-> queue, $ value);}/** (header) departure **/public function removeFirst () {return array_shift ($ this-> queue);}/** clear queue **/public function makeEmpty () {unset ($ this-> queue);}/** get the column header **/public function getFirst () {return reset ($ this-> queue );} /** get the end of a column **/public function getLast () {return end ($ this-> queue);}/** get length **/public function getLength () {return count ($ this-> queue );}}

The above describes how to use php to implement a two-way queue code instance. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.