阅读背景:

利用栈进行括号配对检验

来源:互联网 
Status Test( char *s ) ;

int main()
{
	char s[200]  ;
	gets(s) ;
	if( Test(s) )
		printf("OK\n") ;
	else
		printf("Wrong\n") ;
	return 0 ;
}

Status Test( char *s )
{
	Stack S ;
	char e ;
	InitStack(S) ;
	while( *s != '
Status Test( char *s ) ;

int main()
{
	char s[200]  ;
	gets(s) ;
	if( Test(s) )
		printf("OK\n") ;
	else
		printf("Wrong\n") ;
	return 0 ;
}

Status Test( char *s )
{
	Stack S ;
	char e ;
	InitStack(S) ;
	while( *s != '\0'){
		if( *s == '(' || *s == '[' )
			Push( S, *s ) ;
		else if ( *s == ')'){
			if( Pop(S,e) && e == '(' )
				;
			else
				return ERROR ;
		}
		else if ( *s == ']'){
			if( Pop(S,e) && e == '[' )
				;
			else
				return ERROR ;
		}
		else
			return ERROR ;

		s ++ ;
	}//end while 
	if( StackEmpty(S) )
		return OK ;
	else
		return ERROR ;

}


'){ if( *s == '(' || *s == '[' ) Push( S, *s ) ; else if ( *s == ')'){ if( Pop(S,e) && e == '(' ) ; else return ERROR ; } else if ( *s == ']'){ if( Pop(S,e) && e == '[' ) ; else return ERROR ; } else return ERROR ; s ++ ; }//end while if( StackEmpty(S) ) return OK ; else return ERROR ; } Status Test( char *s ) ; int main() { char s[



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: