括号匹配程序
来源:互联网 发布:东方有线网络客服电话 编辑:程序博客网 时间:2024/04/30 02:47
//均已调试通过,编译器为DEV C++
#include <stdio.h>
#define Stack_Size 100
typedef struct Sqstack{
char *base;
char *top;
int stacksize;
}Sqstack;
//***********创建堆栈*************************
void CreatStack(Sqstack *s)
{
int stacksize; //别忘了
s->base=(char *)malloc(Stack_Size*sizeof(char));
if(!s->base)
exit(1);
s->top=s->base;
stacksize=Stack_Size;
}
//*****************进栈******************
void Push(Sqstack *s,char ch)
{
int stacksize;
if(s->top-s->base>=stacksize)
exit(1);
*(s->top++)=ch;
}
//******************出栈**********************
void Pop(Sqstack *s,char *ch)// //输入参数要以指针方式才能返回数值,否则
//只是原数的复本,修改它原参数不变
{
if(s->base==s->top)
printf("The string is not maching./n");
*ch=*(--s->top);
}
//****************主函数***************************
int main()
{
again: //有问题。。。
printf("Welcome to ues ./n");
Sqstack S;
char ch;
int sign=0;
CreatStack(&S);
printf("please input string:/n");
while((ch=getchar())!='/n')
{
switch(ch){
case'(':Push(&S,'(');
break;
case'[':Push(&S,'[');
break;
case'{':Push(&S,'{');
break;
case')':Pop(&S,&ch);
if(ch!='(')
sign=1;
break;
case']':Pop(&S,&ch);
if(ch!='[')
sign=1;
break;
case'}':Pop(&S,&ch);
if(ch!='{')
sign=1;
break;
default:break;
}
if(sign==1)
break;
}
if(S.base==S.top&&sign==0)
printf("The string is maching./n");
else
printf("The string is not maching./n");
printf("Do you want again(y or n )?/n");
ch=getch();
printf("%c/n",ch);
if(ch=='y'||ch=='Y')
goto again;
return 0;
}
- 括号匹配程序
- C++括号匹配程序
- 括号匹配程序
- 数据结构-括号匹配程序
- 栈 括号匹配程序
- 判断括号匹配程序
- 括号匹配的检验程序
- Java程序练习-括号匹配
- java的括号匹配程序
- C程序括号匹配检查
- 括号括号括号匹配
- 检测程序中的括号是否匹配
- 检测程序中的括号是否匹配
- vs2005 检测程序中的括号是否匹配
- 行编辑程序、括号匹配检验
- 经典c程序(0027)---括号匹配
- 基于栈的括号匹配程序
- 括号匹配
- 正确配置和使用SQL mail
- 踏雪有痕-关系操作符
- 表达式求解程序
- Delphi实现多线程
- 缺陷BUG之母----------- 格蕾丝·霍波
- 括号匹配程序
- BMP文件结构
- 服务级后门自己做
- 给WPF示例图形加上方便查看大小的格子
- Blog搬家
- show desktop short cut
- 说说大型高并发高负载网站的系统架构
- 周杰伦的第8张专辑“我很忙”即将在11月2日推出
- 只让指定的机器连接SQLServer服务器