判断字符串是否对称
来源:互联网 发布:大连新港716火灾知乎 编辑:程序博客网 时间:2024/04/29 00:44
栈实实现检测字符串是否对称
#include<stdio.h>#include<stdlib.h>#define MAX 100typedef struct stack{ char data[MAX]; int top;}SeqStack;void InitStack(SeqStack *&s){ s=(SeqStack*)malloc(sizeof(SeqStack)); s->top =-1;}void ClearStack(SeqStack *&s){ free(s);}int StackLength(SeqStack *&s){ return s->top +1;}int EmptyStack(SeqStack *&s){ return s->top ==-1;}int Push(SeqStack *&s,char ch){ if(MAX-1==s->top) { printf("栈满/n"); exit(1); } else { s->data [++s->top]=ch;// -> has high precdedence to ++ //printf("%c/n",ch); } return 0;}char Pop(SeqStack *&s){ if(-1==s->top ) { printf("栈空/n"); exit(1); } else { return s->data[s->top --]; }}void DispStack(SeqStack *&s){ for(int i=0;i<=s->top;i++) { printf("%c/n",s->data[i]); }}int symmetry(SeqStack *&s,char a[]){ char ch='/0'; int i=0; for(i=0;a[i]!='/0';i++) { Push(s,a[i]); } DispStack(s); for(i=0;a[i]!='/0';i++) { ch=Pop(s); if(a[i]!=ch) { printf("not symmetry!/n"); return 0; } } printf("successfully symmetry/n"); return 1;}int main(){ char a[MAX]={'a','b','c','b','a'};//注意应该为其分配空间, //char a[]={'a','b','c','b','a'}; SeqStack *s; InitStack(s); symmetry(s,a); return 0;}
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断一个字符串是否对称
- Ruby 判断字符串是否对称
- 判断一个字符串是否对称
- 判断一个字符串是否对称
- 判断一个字符串是否是对称字符串
- 【每日面试题】判断字符串是否对称
- 用栈判断字符串是否对称
- 判断字符串是否为对称--双链表
- 1305判断是否为对称字符串
- 黑马程序员_判断一个字符串是否是对称字符串
- java基础题判断一个字符串是否是对称字符串
- 黑马程序员----判断一个字符串是否是对称字符串
- IO/HTML
- str2txt
- 300000 Item randomly get
- 如何编程实现扩展右键菜单之三:调试Shell扩展DLL
- Cannot create JDBC driver of class '' for connect URL 'null'
- 判断字符串是否对称
- IPMI 远程管理
- Oracle基本语法
- 学习css中的摘录
- 用jquey写的简单聊天窗口的例子
- rpm小述
- Oracle创建表
- 就象一个顽皮的孩子重新找回自己心爱的玩具
- 学习xenstore