码迷,mamicode.com
首页 > 编程语言 > 详细

数组的队列和栈方法

时间:2017-03-11 21:58:41      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:gre   html   队列   oct   body   count   out   array   head   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数组的队列和栈方法</title>
</head>
<body>
<script>
// 栈是一种LIFO(Last-In-First-Out后进先出)的数据结构,js中的push()和pop()类似栈的行为
// 队列是一种FIFO(First-In-First-Out先进先出)的数据结构,js中的shift()和unshift()类似队列的行为
// push()和pop()会改变原来的数组,push()方法返回的是数组的长度,pop()方法返回的是数组的最后一项
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>
</html>

数组的队列和栈方法

标签:gre   html   队列   oct   body   count   out   array   head   

原文地址:http://www.cnblogs.com/luoweiling/p/6536235.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!