手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Array栈方法和队列方法的特点说明
Array栈方法和队列方法的特点说明
摘要:栈方法:后进先出(lastinfirstoutside)队列方法:先进先出(firstinfirstoutside)具体应用如下:复制代码代...

栈方法:后进先出(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="栈方法" />

<input type="button" value="队列方法" />

</body>

</html>

【Array栈方法和队列方法的特点说明】相关文章:

JQuery插件jcarousellite的参数中文说明

AngularJs中route的使用方法和配置

js+html5操作sqlite数据库的方法

JQuery控制Radio选中方法分析

基于JavaScript实现智能右键菜单

在JS方法中返回多个值的方法汇总

prototype 的说明 js类

JavaScript中search()方法的使用

JavaScript中String.match()方法的使用详解

js设置document.domain实现跨域的注意点分析

精品推荐
分类导航