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

📄

📁 out< "please input the number of the nodes"<<endl cin>>nodesNum cout<<"pl
💻
字号:
#include"SqStack.h"
#include<stdio.h>
//括号匹配与否的检验,要求表达式中只有两种括号[]和()
int check(){
	SqStack S;   //存放括号
	SElemType e;  
	InitStack(S);//栈的初始化;
	char c;      //存放输入的字符;
	
	while((c=getchar())!='\n'){
		if(c=='('||c=='[') Push(S,c);       //如果是左括号就进栈
		else if(c==')'){
			if(!GetTop(S,e)) return FALSE;//如果栈空,就返回FALSE
			if(e=='(')
               Pop(S,e);                   //退栈
			else if(e=='[')              
				return FALSE;
			
		}//else if
       	else if(c==']'){
			if(!GetTop(S,e))  return FALSE;
			
			if(e=='[')
               Pop(S,e);
			else if(e=='(')
              return FALSE;
		}//else if
        else
			continue;
	}//while
   
	if(StackEmpty(S))     //如果栈空就真确,否则表达式中还有左括号还没有被匹配;		
	    return OK;
	else
		return FALSE;
}


void main()
{
	if(check()) cout<<"Yes"<<endl;
	 else    cout<<"NO"<<endl;
}

⌨️ 快捷键说明

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