用栈结构实现回文数的判断(JavaScript)
封装的方法栈方法:
https://www.cnblogs.com/LIXI-/p/16612874.html
判断回文数:
function isHuiwen(str) { let stack = new Stack(); for (let i = 0; i < str.length; i++) { stack.push(str[i]) } let newstr = "" while(!stack.isEmpty()){ newstr += stack.pop() } return str == newstr } console.log(isHuiwen("abcba"));
打印:
true