栈的应用(括号匹配)
2017-07-11 08:42
316 查看
/****************************************************** Description :Check ()[]{}if match Input :char *pStore OutPut :None Return Value : Calls : Call By : ******************************************************/ void MatchCheck(char * pStore) { SqStack *pST = (SqStack *)malloc(sizeof(SqStack)); int Ret = 0; SElemType stSlem = {0}; SElemType *pGetTopElem = (SElemType*)malloc(sizeof(SElemType)); Ret = InitStack(pST); while(*pStore) { memset(&stSlem,0,sizeof(SElemType)); strcpy(stSlem.cStr,pStore); switch(*pStore) { case '(': case '[': case '{': Ret = Push(pST,stSlem); pStore++; break; case ')': case ']': case '}': Ret = Pop(pST,&pGetTopElem); if((*pGetTopElem->cStr=='(' && *pStore==')')||(*pGetTopElem->cStr=='[' && *pStore==']') || (*pGetTopElem->cStr=='{' && *pStore=='}')) { pStore++; } else { printf("Not Match\n"); return; } break; default: pStore++; break; } } if(IsEmpty(pST)) { printf("Match\n"); } else { printf("Not Match\n"); } DestroyStack(pST); }
相关文章推荐
- 栈应用--括号匹配检测
- (学习笔记)C++括号匹配----栈的应用
- 3.2栈的应用举例----数制转换、括号匹配及行编辑
- 栈的应用之括号匹配
- 括号匹配——栈的基础应用1
- 栈和队列应用之括号匹配
- 数据结构之 栈的应用 括号匹配
- 堆栈应用括号匹配实验
- 数据结构(C语言)读书笔记6:栈的应用之括号匹配的C代码实现
- COJ 1065括号匹配:栈的简单应用
- 栈的简单应用(数制转换、括号匹配检验、行编辑、迷宫求解)
- 栈应用--括号匹配的检验
- 数据结构之SeqStack---堆栈应用---括号匹配问题
- 栈的应用2:检查括号匹配
- 栈的应用——括号匹配的检验(C语言)
- 栈的应用之括号匹配
- 数据结构的应用——使用栈实现字符串括号匹配检查
- 数据结构栈的应用之括号匹配
- 堆栈数据结构应用之括号匹配检查(算法3.2.2)
- 数据结构之 栈的应用 括号匹配