JavaScript栈的实现和回文判断
来源:互联网 发布:clasence 软件 编辑:程序博客网 时间:2024/05/16 16:25
JavaScript栈的实现:
function Stack() { this.dataStore = []; this.top = 0; this.push = function (element) { this.dataStore[this.top++] = element; }; this.pop = function () { return this.dataStore[--this.top]; }; this.peek = function () { return this.dataStore[this.top - 1] }; this.length = function () { return this.top; }; this.clear = function () { this.top = 0; };}
Stack实现回文判断:
回文:一个单词、短语或数字,从前往后写和从后往前写都是一样的
function isPalindrome(word) { if (word === "")return true; if (!word)return false; var s = new Stack; var len = word.length, curr_index = 0; while (curr_index < len) { s.push(word[curr_index++]); } var newWord = ''; while (s.top != 0) { newWord += s.pop(); } return newWord == word;}
console.log("abcd is Palindrome : " + isPalindrome("abcd"));console.log("abcdcba is Palindrome : " + isPalindrome("abcdcba"));
0 0
- JavaScript栈的实现和回文判断
- 用栈和队列实现回文判断
- 判断回文字符串 栈实现
- DS之顺序栈和链队实现回文判断
- 用栈和队列实现判断是否回文
- javaScript实现回文数、水仙花数判断和输出斐波那契数列
- javascript判断回文数
- JavaScript判断回文字符串
- 用数据结构的栈和队列 写 回文判断
- 用C++实现对回文的判断
- 判断回文算法的代码实现
- 利用数组,实现回文数的判断
- 解密回文-数组模拟栈实现简单回文判断
- 只用栈与队列实现判断回文
- 求水仙花数和回文的判断
- 回文词和镜像串的判断
- 回文/回文数的判断
- 利用栈和循环队列判断回文
- HTML5中video-高度宽度
- Network学习7_Java之Pcap文件解析(二:建立数据结构)
- 81. Search in Rotated Sorted Array II
- SDUT 3271 飞花的传送门 (凸包) -- 解题报告
- 导入第三方库和jar
- JavaScript栈的实现和回文判断
- 行内(又称为内联)元素的margin、padding属性值问题
- android 6.0权限
- smarty的分页
- Android获取CPU使用率的几种方式
- IO输出类型
- GOOGLE VR SDK开发VR游戏,VR播放器之一
- DM8148开发板U-boot编译步骤
- PAT 1003