首页 > Web开发 > 详细

js:数据结构笔记3--栈

时间:2014-10-15 10:08:21      阅读:301      评论:0      收藏:0      [点我收藏+]

栈是一种特殊的列表,数据结构为LIFO;

定义:

function Stack() {
   this.dataStore = [];
   this.top = 0;
   this.push = push;
   this.pop = pop;
   this.peek = peek; 
   this.length = length;
   this.clear =clear; 
}
function push(elem) {
   this.dataStore[this.top++] = elem;
}
function pop() {
	var data = this.dataStore[--this.top];
	this.dataStore.length = this.top;
   return data;
}
function peek() {
   return this.dataStore[this.top--];
}
function length() {
   return this.top;
}
function clear() {
   this.top = 0;
}

  

  

js:数据结构笔记3--栈

原文:http://www.cnblogs.com/jinkspeng/p/4025681.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!