kuohaopipei.cpp

来自「用c++描述的顺序存储结构的表,堆栈和队列」· C++ 代码 · 共 48 行

CPP
48
字号
//刮号匹配的检验kuohaopipei.cpp
#include<iostream.h>
#include<malloc.h>
#include<iomanip.h>
#include<stdlib.h>
typedef char Status;
typedef char SElemType;
#include "stack.cpp"
void main()
{SqStack *p;
 int n,m=32,q=0;
 char ch,ca,cd;
 cout<<"kuohaopipei.cpp运行结果:\n";
 cout<<"输入括号字符序列:";
 p->InitStack(&p);
 for(n=1;n<m;n++)
 {cin>>ch;
  if(ch=='[') p->Push(ch);
  if(ch=='(') p->Push(ch);
  if(ch=='{') p->Push(ch);
  if(ch==']')
   {ca=p->Pop(&cd);
    if(ca=='[') cout<<ca<<"与"<<ch<<"是匹配的!\n";
    else
     {cout<<ca<<"与"<<ch<<"不是匹配的!\n";q++;}}
  if(ch==')')
   {ca=p->Pop(&cd);
    if(ca=='(') cout<<ca<<"与"<<ch<<"是匹配的!\n";
    else
     {cout<<ca<<"与"<<ch<<"不是匹配的!\n";q++;}}
  if(ch=='}')
   {ca=p->Pop(&cd);
    if(ca=='{') cout<<ca<<"与"<<ch<<"是匹配的!\n";
    else
     {cout<<ca<<"与"<<ch<<"不是匹配的!\n";q++;}}
  if(p->StackEmpty()) break;}
 if(q>=1) cout<<"刮号序列不匹配!\n";
 else cout<<"刮号序列匹配!\n";
 cin.get();cin.get();}








⌨️ 快捷键说明

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