JavaScript data Structures-stacks and queues

Source: Internet
Author: User

Stack: An ordered set of last in, first out (LIFO) Queue: An ordered set of first in, Out (FIFO)------------------------------------------------------------------------------------------------------ Stack method declaration:First, useArrayTo save the elements in the stack.
sequence number method description
1 push (element (s))
2 pop ()
3 peek () Returns the element at the top of the stack without any modifications to the stack
4 isempty ()
5 clear () Remove all elements from the stack
6 size ()
For collections, it is best to use size instead of length the implementation of the stack: Queue method declaration:First, useArrayTo save the elements in the stack.
Serial number Method Description
1 Enqueue (Element (s)) Add one (or more) new items to the tail of the queue
2 Dequeue () Removes the first (that is, the top of the queue) item in the queue and returns the removed element
3 Front () Returns the first element in a queue--first added, no changes to the queue
4 IsEmpty () Returns true if there are no elements in the queue, otherwise false
5 Size () Returns the number of elements in the queue. The length property of the array is very similar
implementation of the queue:

JavaScript data Structures-stacks and queues

Related Article

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.