博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javasript_数据结构和算法_栈
阅读量:4507 次
发布时间:2019-06-08

本文共 996 字,大约阅读时间需要 3 分钟。

1 //-----------------------------------存储结构为数组-------------------------------------------- 2 function Stack(){ 3     this.store = []; 4     this.top = 0; 5     this.push = push; 6     this.pop = pop; 7     this.display = display; 8     this.length = length; 9 10     this.binary_10 = binary_10;11 }12 13 function push(ele){14     this.store[this.top] = ele;15     this.top++;  //top指向下一个元素16 }17 function pop(){18     return this.store[--this.top];19 }20 function peek(){21     return this.store[this.top-1];22 }23 function length(){24     return this.top;25 }26 function display(){27     for(var i=this.length()-1; i>-1; i--){28         console.log(this.store[i]);29     }30 }31 function binary_10(){32     var sum = 0;33     var j = 0;34     for(var i=this.top-1; i>-1; i--){35         sum += this.store[i] * Math.pow(2,j);36         j++;37     }38     return sum;39 }40 var stack = new Stack();41 var num = '11001001';42 for(var i=0; i

 

转载于:https://www.cnblogs.com/cai-yu-candice/p/6243150.html

你可能感兴趣的文章
Memcached学习(一)--网络模型
查看>>
FragmentTransaction add 和 replace 区别 转
查看>>
html5及css3开发性能问题
查看>>
使用python发送邮件
查看>>
【转】java虚拟机内存原型
查看>>
2018年最新Java面试题及答案整理(持续完善中…)
查看>>
什么是构造函数,什么是析构函数,作用是什么。
查看>>
C# 想要程序文件移动 而数据保持相对位置
查看>>
功能连接分析论文
查看>>
消息称各中央单位落户北京指标今年压缩17%
查看>>
记一次IIS站点出错的解决过程
查看>>
jQuery 效果方法
查看>>
STM32物联网通信WIFI
查看>>
java反射案例详解
查看>>
MAGENTO 与 reindexer
查看>>
Oracle笔记之——常用的函数及脚本
查看>>
SQLServer2008 关于Having
查看>>
关于express中的中间件
查看>>
mtr语言真是逆天了
查看>>
input模糊匹配 组件赋值问题
查看>>