例3.4 使用栈判断回文
来源:互联网 发布:广州sd卡数据恢复 编辑:程序博客网 时间:2024/05/20 18:44
//栈类class Stack{ final int MaxSize = 10; char[] str;// 栈 int top; // 栈顶指针 public Stack() { str = new char[MaxSize]; top = -1; // 初始值为-1 } // 进栈 public void Push(char c) { if (top == MaxSize - 1) { System.out.println("Error: Out of MaxSize"); return; } top++; str[top] = c; } // 出栈 public char Pop() { if (top == -1) { System.out.println("Error:Empty Stack"); return '0'; } char c = str[top]; top--; return c; } // 显示栈中元素 public void DispStack() { for (int i = top; i > 0; i--) System.out.print(str[i] + " "); System.out.println(); }}public class MyStack{ public static void main(String args[]) { String s = "12321"; System.out.println(IsHuiWen(s)); } public static boolean IsHuiWen(String s) { Stack stack = new Stack(); char c; for (int i = 0; i < s.length(); i++) stack.Push(s.charAt(i)); for (int i = 0; i < s.length(); i++) { c = stack.Pop(); if (c != s.charAt(i)) return false; } return true; }}
输出:
true
0 0
- 例3.4 使用栈判断回文
- 使用栈判断回文
- C++ 使用栈判断回文字符串
- 判断回文字符序列-栈的使用
- 使用栈与队列判断回文串
- 栈---回文判断
- 用栈判断回文
- 栈--判断回文字符串
- 判断回文字符串(栈)
- 栈 判断回文序列
- 【算法】回文数的判断--栈的使用
- 【数据结构】使用栈和队列判断字符串是否是回文
- 栈初探(判断回文)
- 判断一个栈是不是回文
- 利用栈判断回文数。
- 判断回文字符串 栈实现
- 使用堆栈判断字符串是否回文
- JavaScript使用正则表达式判断回文字符串
- php Smarty模板引擎配置与测试
- php改良判断网站是否被百度收录
- iOS 设置uitextField的placehold的字体颜色和字体大小
- 命令行菜单小程序V1.0
- 第十一周项目4哈夫曼编码的算法验证
- 例3.4 使用栈判断回文
- 第九周实践项目2—对称矩阵压缩存储的实现与应用(2)
- ftp提取文件到hdfs
- java面向对象之继承
- Hibernate快速上手
- Ionic中集成和卸载 Crosswalk
- 黑马程序员——IO——File、常用流对象演示
- Codeforces Round #330 (Div. 2)B Pasha and Phone
- Cocoapods第三方库快速集成