ss_khpp.cpp

来自「数据结构中所有算法的实现」· C++ 代码 · 共 38 行

CPP
38
字号
#include "ss.cpp"

void Match(char a[]){
  int i=0;
  SqStack S;
  ElemType e1,e2,e3;
  InitStack(S);
  printf("\n%s\n",a);
  while(a[i]!='\0'){
    e1=a[i];
    switch(e1){
      case '(':
	Push(S,e1);i++;break;
      case '[':
	Push(S,e1);i++;break;
      case ')':
	if(!GetTop(S,e2)){printf("NOT MATCH!");	exit(ERROR);}
	if(e2=='('){Pop(S,e3);i++;break;}
	else{printf("NOT MATCH!"); exit(ERROR);}
      case ']':
	if(!GetTop(S,e2)){printf("NOT MATCH!");	exit(ERROR);}
	if(e2=='['){Pop(S,e3);i++;break;}
	else{printf("NOT MATCH!"); exit(ERROR);}
      default:
	i++;
    }//switch
  }//while
  if(S.top==S.base)printf("VERY GOOD! IT IS MATCHED!");
  else printf("NOT MATCH!");
}

void main(){
 
  char bds[]="(([(([[e]g])))])";

  Match(bds);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?