Array棧方法和隊列方法的特點說明

來源:互聯網
上載者:User

 本篇文章主要是對Array棧方法與隊列方法的特點進行了詳細的說明介紹,需要的朋友可以過來參考下,希望對大家有所協助

棧方法:後進先出(last in first outside) 隊列方法:先進先出(first in first outside) 具體應用如下:  代碼如下:<!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>棧方法</title>    <script type="text/javascript">        //棧是一種LIFO(last in first outside)後進先出的資料結構       function basicPushOrPop(){         var colors=["red","green","blue"];         var count=colors.push("pink");//push()方法可以接收任意數量的參數,並把它們逐個添加到資料的末尾,並返回修改後數組的長度         alert(count);          var temp=colors.pop();//pop()方法則從數組末尾移除最後一項,減少數組的length值,然後返回移除的項         alert(temp);       }        //隊列資料結構的訪問規則是FIFO(first in first outside)       function basicShift(){          var colors=new Array();          var count=colors.push("red","blue");//推入兩項          alert(count);           var temp=colors.shift();//取的隊列中第一項的資料,並移除          alert("現在數組長度為:"+colors.length+"--移除的項為:"+temp);           var newcount=colors.unshift("green","black");//unshift方法表示在隊列前端添加任意個任意類型的值,並返回新的數組長度          alert("現在數組長度為:"+newcount);//ie unshift方法總是返回undefined       }    </script></head><body>  <input type="button" value="棧方法" onclick="basicPushOrPop();" />  <input type="button" value="隊列方法" onclick="basicShift();" /></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.