The characteristic explanation of array stack method and queue method

Source: Internet
Author: User
Tags array length

  This article is mainly on the array stack method and the characteristics of the queue method is described in detail, the need for friends can come to the reference, I hope to help you.

Stack method: LIFO (last in first outside)   queue method: FIFO (first-in-outside)   specific applications are as follows:     code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head>     <title> Stack method </title>     <script type= "Text/javascript" >        //Stack is a LIFO (last in first outside) data knot Construction        function Basicpushorpop () {         var colors=["Red", "green", "blue "];          var count=colors.push ("Pink"); the//push () method can receive any number of parameters and add them one at the end of the data and return the length of the modified array          alert (count);            var Temp=colors.pop (); the//pop () method removes the last item from the end of the array, reduces the length of the array, and then returns the removed item          alert (temp);       &NBSP}          //queue data structure access rule is FIFO (in FirsT outside)        function Basicshift () {        var colors=new Array (); &n Bsp         var count=colors.push ("Red", "blue");/push two           alert (count);             var temp=colors.shift ()//data from the first item in the queue, and remove    ,       Ale RT ("Now the array length is: +colors.length+"--The removed item is: "+temp);"             var newcount=colors.unshift ("Green", "Black"); the//unshift method represents adding any value of any type to the front of the queue. and returns the new array length           alert ("Now the array length is:" +newcount);//ie Unshift method always returns undefined       &NBSP}     </script> </head> <body>   <input type= "button" value= "Stack Method" onclick= " Basicpushorpop (); "/>   <input type=" button "value=" Queue method "onclick=" Basicshift (); "/> </body> </ Html>

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.