文档详情

C++表达式括号匹配.doc

发布:2018-03-05约小于1千字共3页下载文档
文本预览下载声明
#includeiostream using namespace std; #includestring.h class SeqStack { public : SeqStack(){top=-1;} ~SeqStack(){} void Push(char x); char Pop(); private : int data[20]; int top; }; void SeqStack::Push(char x)//P { top++; data[top]=x; } char SeqStack::Pop()//D { int t; t=top; top--; return data[t]; } int main() { SeqStack A; int n,i,count=0,k,t; char str[50]; while(cinstr) { k=0; t=0; n=strlen(str); for(i=0;in;i++) { if(str[i]==() { k++; str[i]=); A.Push(str[i]); } else if(str[i]==)) { if(A.Pop()==)) {t++;} } } if(k==t) coutOKendl; else coutNOendl; count++; } return 0; }
显示全部
相似文档