Queue and Stack methods for arrays

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Queue and Stack methods for arrays </title>
<body>
<script>
The stack is a LIFO (LAST-IN-FIRST-OUT LIFO) data structure, and the behavior of the push () and pop ()-like stacks in JS
queue is a FIFO (first-in-first-out first-out) data structure, JS Shift () and unshift () similar to the behavior of the queue
push () and pop () change the original array, the push () method returns the length of the array, and the Pop () method returns the last item of the array
var colors = new Array ();
var count = Colors.push (' Red ', ' yellow ');
alert (count); 2

Count = Colors.push (' black ');
alert (count); 3
var item = Colors.pop ();
alert (item); " Black
alert (colors.length); 2

Colors.push (' Blue ', ' green ');
var first = Colors.shift ();
alert (first); Red
Colors.unshift (' white ');
alert (colors); White,yellow,blue,green
</script>
</body>

Queue and Stack methods for arrays

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.