⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bracketmatching.cpp

📁 这是本人精心搜集的关于常用图论算法的一套源码
💻 CPP
字号:
//Bracket Matching Program
int main( )
/* Post: The program has notified the user of any bracket mismatch in the standard inputfile.
   Uses: The classStack . */
{   Stack openings;
    char symbol;
    bool is_matched = true;
    while(is_matched && (symbol=cin.get( )) != '\n')
       {
        if(symbol=='{' || symbol=='(' || symbol=='[')
           openings.push(symbol);
        if(symbol=='}' || symbol==')' || symbol==']')
          {
           if(openings.empty( ))
             { is_matched = false;
               cout<<"Unmatched closing bracket"<<symbol<<" detected.\n";
             }
           else
             { char match;  
               openings.top(match);
               openings.pop( );
               is_matched=(symbol=='}' && match=='{')||(symbol==')' && match=='(')||(symbol==']' && match =='[');
               if(!is_matched)
               cout<<"Bad match "<<match<< symbol<<endl;
              }   
          } //end_if(symbol=='}' ...
       }   //end_while
    if(!openings.empty( )) cout<<"Unmatched opening bracket(s) detected.\n";  
}

⌨️ 快捷键说明

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