Stack and queue

Source: Internet
Author: User
Unlike other languages in JS, JS does not have a dedicated stack and queue type. All stacks and queues are stacks simulated by Arrays: closed at one end, the special array that can only be imported from the other end is called the first in last out of the stack. It features the last out of the stack: when to use: If you want to always use the latest elements, the stack structure is required. How to use: 1. From the end to the stackInbound stack (pressure stack): arr. push (value) outbound stack (bullet stack): var last = arr. pop () features: no influence on the position of the remaining elements, whether it is an outbound stack or an inbound Stack 2. Access the stack from the beginning,Inbound Stack: arr. unshift (value); out Stack: var first = arr. the disadvantage of shirt () is that every time the stack goes in and out, the position of other elements changes. Let's test whether push and unshift can be pushed into multiple values at a time? Can I scatter the array and press it in? The array parameters will not be split, and the push and unshift parameters will not be split. It is pressed into a suite. Then, can we press on two elements? This can be multiple values, but the full example of array parameters is not supported in the stack: (note the difference between push and unsfitf) mainly depends on the execution sequence. Queue: the array that enters from the end and comes out from the beginning. When to use first in first out: when to use elements in the order of first in, first in, and then in the queue: arr. push (); 2. output queue: var first = arr. shift ();

 

Stack and queue

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.