Queue and Stack: two stack implementation queue, two queue implementation stack

Source: Internet
Author: User
1. Title: implement a queue with two stacks . First with a stack input data, and then output this stack to another stack, you can form a queue of FIFO order.

Because the PHP array can emulate the implementation of the stack, the code is as follows:

 
 2. implement a stack with two queues . The order of the stacks is mainly advanced after-out. First with a queue input data, and then each time the data to transfer the a queue of data to B queue, a queue only left the last number, and then the a queue of data out of the team is the last element. Each time the data is transferred back and forth to the queue.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the queue and stack: two stack implementation queue, two queue implementation stack, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.