function Stack() {
var items = [];
this.push = function(item) {
items.push(item)
}
this.pop = function() {
return items.pop()
}
this.peek = function() {
return items[items.length - 1]
}
this.isEmpty = function() {
return items.length == 0
}
this.size = function() {
return items.length
}
this.clear = function() {
items = []
}
this.printf = function() {
console.log(items.toString())
}
this.divideBy2 = function(decNumber) {
var remStack = new Stack(),
rem,
binaryString = '';
while (decNumber > 0) {
rem = Math.floor(decNumber % 2);
remStack.push(rem);
decNumber = Math.floor(decNumber / 2)
}
while (!remStack.isEmpty()) {
binaryString += remStack.pop().toString()
}
return binaryString
}
}
var stacks = new Stack();
console.log(stacks.isEmpty());
stacks.push(5);
stacks.push(4);
console.log(stacks.peek());
stacks.push(11);
console.log(stacks.size());
console.log(stacks.isEmpty());
stacks.push(15);
stacks.pop();
console.log(stacks.size());
stacks.printf();
console.log(stacks.divideBy2(33));

  

JavaScript Stack的更多相关文章

  1. [Algorithom] Stack Data Structure in JavaScript

    A stack is a collection of items that obeys the principle of "last in, first out". Like a ...

  2. JavaScript 查看stack trace

    How can I get a JavaScript stack trace when I throw an exception? Edit 2 (2017): In all modern brows ...

  3. JavaScript取子串方法slice,substr,substring对比表

    在程序语言中,字符串可以说是最常用的一种类型,而在程序中对字符串的操作也是十分频繁.当程序语言自带多种字符串操作的方法时,用该语言编程程序时就有很多的便利性,提高开发的效率.但是当方法过多,甚至目的相 ...

  4. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  5. Cheatsheet: 2015 09.01 ~ 09.30

    Web A Guide to Vanilla Ajax Without jQuery Gulp for Beginners A Detailed Walkthrough of ASP.net MVC ...

  6. [Ramda] Lens in Depth

    In this post, we are going to see how to use Ramda Lens. For example, we have data: const {log} = re ...

  7. 摘录和再编:彻底弄懂JS执行机制

    网文: https://juejin.im/post/59e85eebf265da430d571f89 并发模型和事件循环:https://developer.mozilla.org/zh-CN/do ...

  8. [React] 05 - Route: connect with ExpressJS

    基础: 初步理解:Node.js Express 框架 参见:[Node.js] 08 - Web Server and REST API 进阶: Ref: 如何系统地学习 Express?[该网页有 ...

  9. Web 前端从入门菜鸟到实践老司机所需要的资料与指南合集

    http://web.jobbole.com/89188/ 2016 – 对于未来五年内Web发展的7个预测 2015 – 我的前端之路:从命令式到响应式,以及组件化与工程化的变革 怎么成为一名优秀的 ...

随机推荐

  1. 2019 Multi-University Training Contest 1 - 1009 - String - 贪心

    不知道错在哪里. 是要把atop改成stop!两个弄混了.感谢自造样例. #include<bits/stdc++.h> using namespace std; typedef long ...

  2. jquery实现表单验证与页面加载之后执行渲染

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 【JAVA】 04-Java中的多线程

    链接: 笔记目录:毕向东Java基础视频教程-笔记 GitHub库:JavaBXD33 目录: <> <> 内容待整理: 多线程引入 概述 多线程: 进程:正在执行中的程序,其 ...

  4. Ajax异步请求返回文件流(eg:导出文件时,直接将导出数据用文件流的形式返回客户端供客户下载)

    在异步请求中要返回文件流,不能使用JQuery,因为$.ajax,$.post 不支持返回二进制文件流的类型,可以看到下图,dataType只支持xml,json,script,html这几种格式,没 ...

  5. scp - 安全复制(远程文件复制程序)

    总览 SYNOPSIS scp -words [-pqrvBC1246 ] [-F ssh_config ] [-S program ] [-P port ] [-c cipher ] [-i ide ...

  6. 工作中常用的linux命令大全

    文章内容参考:https://www.cnblogs.com/yjd_hycf_space/p/7730690.html  谢谢大佬的分享 系统信息  date  显示系统日期 cal + 年份 显示 ...

  7. 联想笔记本 thinkpad BIOS 超级密码 Supervisor Password 清除 破解 亲测有效 转载地址https://blog.csdn.net/ot512csdn/article/details/72571674

    联想笔记本 thinkpad BIOS 超级密码 Supervisor Password 清除 破解 亲测有效 转载地址https://blog.csdn.net/ot512csdn/article/ ...

  8. 开源Futter项目

    前段时间Flutter很火,所以在闲暇之余做了一个助学通的Flutter移动端应用,现在开源出来,希望对想要学习Flutter的朋友有所帮助. 我大致做个项目介绍: 学生签到系统:分java服务端提供 ...

  9. 【串线篇】加谈数据库之连接join

    主题:内连接.左连接(左外连接).右连接(右外连接) 建表语句: CREATE TABLE `a_table` (  `a_id` int(11) DEFAULT NULL,  `a_name` va ...

  10. kaildi讲解

    转载声明:本文为转载文章 作者:ferb2015 原文地址:https://blog.csdn.net/eqiang8848/article/details/81543599 kaldi是一个开源的语 ...