栈(stack)是一种运算受限的线性表。栈内的元素只允许通过列表的一端访问,这一端被称为栈顶,相对地,把另一端称为栈底。装羽毛球的盒子是现实中常见的栈例子。栈被称为一种后入先出(LIFO,last-in-first-out)的数据结构。向一个栈插入新元素又称作进栈、入栈或压栈,它是把新元素放到栈顶元素的上面,使之成为新的栈顶元素;从一个栈删除元素又称作出栈或退栈,它是把栈顶元素删除掉,使其相邻的元素成为新的栈顶元素。

  下图演示了入栈和出栈的过程:

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGUAAAHkCAIAAAAYXAXTAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAADZlSURBVHhe7d3RoZu4EgDQrSsFpZ5Uk2ZSzHtCkkHA2MY2cAGf85EYAUKawYLZJHf/+x8AAAAR9RIAAEBMvQQAABAb6qX/AAAAuOmqpFIsJWUbAAAA9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSw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fUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADE1EsAAAAx9RIAAEBMvQQAABBTLwEAAMTUSwAAADH1EgAAQEy9BAAAEFMvAQAAxNRLAAAAMfUSAABATL0EAAAQUy8BAADEgnoJAACAoquSSrEEAADAhHoJAAAgpl4CAACI/O9//wceqdd0dZPBpAAAAABJRU5ErkJggg==" alt="" />

  我们知道pop()方法虽然可以访问栈顶元素,但是调用该方法后,栈顶元素被删除,而peek()方法返回栈顶元素,并不改变栈。push(),pop(),peek()是实现栈的三个主要方法,下表定义了栈的主要方法:

主要方法及属性
dataStorage Array 存储数据的底层数据结构
top int 记录栈顶元素位置
push fucntion 入栈方法
pop fucntion 出栈方法
peek fucntion 返回栈顶元素
length     fucntion   返回栈内元素个数
clear function   清空栈元素

  

 

 

栈的实现

  构造方法:  

 function Stack() {
this.dataStorage = [];
this.top = 0;
this.push = push;
this.pop = pop;
this.peek = peek;
this.length = length;
this.clear = clear;
}

  我们用数组来存储栈内元素,构造方法将其初始化为一个空数组,变量top记录栈顶元素位置,被构造方法初始化为0,表示栈顶元素的初始位置为0,当有元素入栈,top也随之改变。

  push()方法的实现:  

 function push(element) {
this.dataStorage[this.top++] = element;//将元素保存在数组top位置,并指向下一空位置
}

  当向栈中压入一个新元素时,需要将其保存在数组中变量 top 所对应的位置,然后将 top 值加 1,让其指向数组中下一个空位置。这里要特别注意 ++ 操作符的位置,它放在 this.top 的后面,这样新入栈的元素就被放在top 的当前值对应的位置,然后再将变量 top 的值加 1,指向下一个空位置。

  pop方法的实现:  

 function pop() {
return this.dataStorage[--this.top];//返回数组top位置的元素,并让top指向top-1位置元素
}

  pop() 方法恰好与 push() 方法相反——它返回栈顶元素,同时将变量 top 的值减 1。

  peek() 方法的实现:  

 function peek() {
return this.dataStorage[this.top-1];//返回数组top-1位置的元素
}

  这里需要考虑到空栈调用peek方法时候,返回的是-1位置元素,为undefined。

  length()方法的实现:  

 function length() {
return this.top;
}

  如果需要知道栈内到底存了多少个元素,可通过调用length()方法,栈元素的个数即top的值。

  清空栈clear()饭方法的实现:

 function clear() {
this.top = 0;
}

  将top设置为0,即栈顶元素位置为0,此时为空栈。

  下面我们来测试下: 

         var s = new Stack();
s.push("a");//向栈顶压入元素
s.push("b");
s.push("c");
console.log(s.length());//输出栈内元素个数
console.log(s.pop());//返回栈顶元素并删除
console.log(s.length());
console.log(s.peek());//返回栈顶元素不删除
s.clear();
console.log(s.length());
console.log(s.peek());

  输出结果:

  

  最后一行返回undefined,是因为栈内元素被清空后,栈顶无值。

  Stack实际应用  

  我们来模拟一个简单的递归过程,计算数的阶乘。

  先使用递归实现:  

 function Factorial(num) {
if (num == 0) {
return 1;//0的阶乘为1
} else {
return num*Factorial(num - 1);
} }

  用栈来计算,首先需要将数字1~num全部压入栈,然后将数字连乘。 

         function StackFactorial(num) {
var stack = new Stack();
while (num > 1) {
stack.push(num--);//将1~num压入栈
}
var result = 1;
while (stack.length() > 0) {
result *= stack.pop();//连乘从栈顶取出的元素
}
return result;
}

  测试结果:  

 console.log(Factorial(10));//输出3628800
console.log(StackFactorial(10));//输出3628800

  本文的示例代码地址:https://github.com/LJunChina/JavaScript

JavaScript数据结构——栈的实现的更多相关文章

  1. JavaScript数据结构——栈和队列

    栈:后进先出(LIFO)的有序集合 队列:先进先出(FIFO)的有序集合 --------------------------------------------------------------- ...

  2. javascript数据结构——栈

    栈是一种高效的数据结构,数据只能在栈顶添加或删除,所以这样操作很快,也很容易实现.栈的使用遍布程序语言实现的方方面面,从表达式求值到处理函数调用.接下来,用JavaScript实现一个栈的数据结构. ...

  3. JavaScript数据结构——栈的实现与应用

    在计算机编程中,栈是一种很常见的数据结构,它遵从后进先出(LIFO——Last In First Out)原则,新添加或待删除的元素保存在栈的同一端,称作栈顶,另一端称作栈底.在栈中,新元素总是靠近栈 ...

  4. javascript数据结构-栈

    github博客地址 栈(stack)又名堆栈,它是一种运算受限的线性表.遵循后进先出原则,像垃圾桶似的.功能实现依然按照增删改查来进行,内部数据存储可以借用语言原生支持的数组. 栈类 functio ...

  5. JavaScript数据结构——队列的实现

    前面楼主简单介绍了JavaScript数据结构栈的实现,http://www.cnblogs.com/qq503665965/p/6537894.html,本次将介绍队列的实现. 队列是一种特殊的线性 ...

  6. JavaScript数据结构——字典和散列表的实现

    在前一篇文章中,我们介绍了如何在JavaScript中实现集合.字典和集合的主要区别就在于,集合中数据是以[值,值]的形式保存的,我们只关心值本身:而在字典和散列表中数据是以[键,值]的形式保存的,键 ...

  7. JavaScript数据结构——图的实现

    在计算机科学中,图是一种网络结构的抽象模型,它是一组由边连接的顶点组成.一个图G = (V, E)由以下元素组成: V:一组顶点 E:一组边,连接V中的顶点 下图表示了一个图的结构: 在介绍如何用Ja ...

  8. javascript数据结构

    学习数据结构非常重要.首要原因是数据结构和算法可以很高效的解决常见问题.作为前端,通过javascript学习数据结构和算法要比学习java和c版本容易的多. 在讲数据结构之前我们先了解一下ES6的一 ...

  9. 学习javascript数据结构(一)——栈和队列

    前言 只要你不计较得失,人生还有什么不能想法子克服的. 原文地址:学习javascript数据结构(一)--栈和队列 博主博客地址:Damonare的个人博客 几乎所有的编程语言都原生支持数组类型,因 ...

随机推荐

  1. ACE首页更改

    @{ Layout = null; } <!DOCTYPE html> <html lang="zh-cn"> <head> <meta ...

  2. permeation开篇

    学习方法: To follow the path look to the master follow the master walk with the master see through the m ...

  3. Objective-C处理动态类型函数集

    -(BOOL) isKindOfClass:class-object 对象是不是class-object或其子类的实例-(BOOL) isMemberOfClass:class-object 对象是不 ...

  4. 递归编译的Makefile的实现

    最近写了一个递归Makefile,目的是既可以实现子模块的单独编译,也可以不做任何修改就和整个程序的整体进行无缝衔接的编译.具体的思路是借助第三方文件,将子模块编译好的.o文件的路径自动写到confi ...

  5. Unity3D中如何计算场景中的三角面和顶点数

    在做游戏开发时,场景中的三角面和顶点数影响着运行效率,尤其是在手机平台上,实时的知道场景中的各项指标,对性能优化来说至关重要,下面我们来实现一个小功能,来实时计算场景中的三角面和顶点数: 如果要知道场 ...

  6. Apache Arrow 内存数据

    1.概述 Apache Arrow 是 Apache 基金会全新孵化的一个顶级项目.它设计的目的在于作为一个跨平台的数据层,来加快大数据分析项目的运行速度. 2.内容 现在大数据处理模型很多,用户在应 ...

  7. Unity3d获取游戏对象的几种方法

    1.GameObject.Find() 通过场景里面的名子或者一个路径直接获取游戏对象. GameObject root = GameObject.Find("GameObject" ...

  8. 【thinkphp 5 在nginx 环境下路由无法生效(404 500错误 )的解决方法】

      非常惭愧的说,由于之前一直使用的是windowservice,安装apache来进行服务器布置的,这种方式也是最简单最直接的方式, 但是由于php的服务大多都是linux栈的,咱们也不能落后呀,在 ...

  9. Eclipse 报java.lang.UnsupportedClassVersionError: ("yourclass") bad major version at offset=6

    报这个错误是指你的jar包或者class 的被编译的jdk版本比当前runtime的jdk版本高. 解决问题 1)如果是jar包,重新用jdk 1.6编译你的jar 包 2)如果是java文件或者项目 ...

  10. ajax问题

    1. 代码:var i;for(i=0;i<10;i++){      ajaxServise(i);} 在for循环中调用ajax方法  补充页面上的数据,这样写是错误的,他不会每执行一次fo ...