第五周 项目3 - 括号的匹配
2017-10-15 21:32
141 查看
#include <stdio.h>
#include "sqstack.h"
int main()
{
char c;
char st[50];
int d=1, i;
SqStack *s;
InitStack(s);
printf("请输入表达式:");
scanf("%s", st);
for(i=0; st[i]!='\0'&&d; i++)
{
switch(st[i])
{
case'(':
case'[':
case'{':
Push(s, st[i]);
break;
case')':
Pop(s, c);
if(c!='(') d=0;
break;
case']':
Pop(s, c);
if(c!='[') d=0;
break;
case'}':
Pop(s,c);
if(c!='{') d=0;
break;
}
}
if(StackEmpty(s)&&d==1)
printf("配对正确!!\n");
else
printf("配对错误!!\n");
return 0;
}
#include "sqstack.h"
int main()
{
char c;
char st[50];
int d=1, i;
SqStack *s;
InitStack(s);
printf("请输入表达式:");
scanf("%s", st);
for(i=0; st[i]!='\0'&&d; i++)
{
switch(st[i])
{
case'(':
case'[':
case'{':
Push(s, st[i]);
break;
case')':
Pop(s, c);
if(c!='(') d=0;
break;
case']':
Pop(s, c);
if(c!='[') d=0;
break;
case'}':
Pop(s,c);
if(c!='{') d=0;
break;
}
}
if(StackEmpty(s)&&d==1)
printf("配对正确!!\n");
else
printf("配对错误!!\n");
return 0;
}
相关文章推荐
- 第五周 项目三 括号的匹配
- 第五周项目三C/C++数据结构实践——括号的匹配(栈)
- 第五周项目3-括号的匹配
- 第五周项目3括号的匹配
- 数据结构第五周项目-括号的匹配
- 第五周项目三——括号的匹配
- 第五周项目3 括号的匹配(1)
- 第五周项目3---括号的匹配
- 第五周项目3--括号的匹配
- 第五周项目三—括号的匹配
- 第五周项目3—— 括号的匹配
- 第五周--项目3-括号的匹配
- 第五周项目三-括号的匹配
- 第五周- 项目三 括号的匹配
- 第五周项目三-括号的匹配(栈)
- 【第五周】项目3-括号的匹配
- 第五周—项目3——括号的匹配
- 第五周项目3--括号的匹配
- 第五周-项目3 - 括号的匹配
- 第五周——项目三—括号的匹配