資源簡介
數據結構 嚴蔚敏 C語言版 括號匹配
while((c = getchar()) != EOF)
{
switch(c)
{
case '[':
push(&sqSta;, c);
break;
case '(':
push(&sqSta;, c);
break;
case ']':
if(getTop(&sqSta;, &e))
{
if(e == '[')
{
pop(&sqSta;, &temp;);
}
if(e == '(')
{
printf("\nnot match\n");
return ERROR;
}
}
break;
case ')':
if(getTop(&sqSta;, &e))
{
if(e == '(')
{
pop(&sqSta;, &temp;);
}
if(e == '[')
{
printf("\nnot match\n");
return ERROR;
}
}
break;
default :
printf("\nerror\n");
return ERROR;
break;
}
}
if(stackEmpty(sqSta))
{
printf("\nmatched\n");
}
else
{
printf("\nnot matched\n");
}

代碼片段和文件信息
#include?
#include?
#include?“seqStack.h“
status?main()
{
char?cetemp;
seqStack?sqSta;
initStack(&sqSta);
while((c?=?getchar())?!=?EOF)
{
switch(c)
{
case?‘[‘:
push(&sqSta?c);
break;
case?‘(‘:
push(&sqSta?c);
break;
case?‘]‘:
if(getTop(&sqSta?&e))
{
if(e?==?‘[‘)
{
pop(&sqSta?&temp);
}
if(e?==?‘(‘)
{
printf(“\nnot?match\n“);
return?ERROR;
}
}
break;
case?‘)‘:
if(getTop(&sqSta?&e))
{
if(e?==?‘(‘)
{
pop(&sqSta?&temp);
}
if(e?==?‘[‘)
{
printf(“\nnot?match\n“);
return?ERROR;
}
}
break;
default?:
printf(“\nerror\n“);
return?ERROR;
break;
}
}
if(stackEmpty(sqSta))
{
printf(“\nmatched\n“);
}
else
{
printf(“\nnot?matched\n“);
}
return?OK;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7391??2013-01-10?12:50??bracketMatch\huan
?????文件????????865??2013-01-10?12:50??bracketMatch\main.c
?????文件???????1609??2013-01-10?12:50??bracketMatch\seqStack.h
?????目錄??????????0??2013-01-16?11:47??bracketMatch
-----------?---------??----------?-----??----
?????????????????9865????????????????????4
- 上一篇:C++圖像二值化代碼
- 下一篇:簡單實現的LZ78編碼程序
評論
共有 條評論