#include<stdio.h>
#include<string.h>
#define MaxStackSize 100
typedef char DataType;
typedef struct
{
DataType stack[MaxStackSize];
int top;
}SeqStack;
#include"SeqStack.h"
void ExpIsCorrect(char exp[],int n);
void main()
{
char a[]="(())abc{[]()}";
char b[]="(()))abc{[]}";
char c[]="(()()abc{[]}";
char d[]="(())abc{[]}";
int n1=strlen(a);
int n2=strlen(b);
int n3=strlen(c);
int n4=strlen(d);
ExpIsCorrect(a,n1);
ExpIsCorrect(b,n2);
ExpIsCorrect(c,n3);
ExpIsCorrect(d,n4);
}
void ExIsCorrect(char exp[],int n)
{
SeqStack myStack;
int i;
char c;
StackInitiate(&myStack);
for(i=0;i<n;i++)
{
{
if((exp[i]=='(')||(exp[i]=='[')||(exp[i]=='{'))
StackPush(&myStack,exp[i]);
else if(exp[i]==')'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c=='(')
StackPop(&myStack,&c);
else if(exp[i]==')'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c!='(')
{
printf("左右括号配对次序不正确!\n");
return;
}
else if(exp[i]==']'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c=='[')
StackPop(&myStack,&c);
else if(exp[i]==']'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c!='[')
{
printf("左右括号配对次序不正确!\n");
return;
}
else if(exp[i]=='}'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c=='{')
StackPop(&myStack,&c);
else if(exp[i]=='}'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c!='{')
{
printf("左右括号配对次序不正确!\n");
return;
}
else if(((exp[i]==')')||(exp[i]==']')||(exp[i]'}'))&&!StackNotEmpty(myStack))
{
printf("右括号多于左括号!\n");
return;
}
}
if(StackNotEmpty(myStack))
printf("左括号多于右括号!\n");
else
printf("左右括号匹配正确!\n");
}
syntax error : missing ')' before 'constant'
#include<string.h>
#define MaxStackSize 100
typedef char DataType;
typedef struct
{
DataType stack[MaxStackSize];
int top;
}SeqStack;
#include"SeqStack.h"
void ExpIsCorrect(char exp[],int n);
void main()
{
char a[]="(())abc{[]()}";
char b[]="(()))abc{[]}";
char c[]="(()()abc{[]}";
char d[]="(())abc{[]}";
int n1=strlen(a);
int n2=strlen(b);
int n3=strlen(c);
int n4=strlen(d);
ExpIsCorrect(a,n1);
ExpIsCorrect(b,n2);
ExpIsCorrect(c,n3);
ExpIsCorrect(d,n4);
}
void ExIsCorrect(char exp[],int n)
{
SeqStack myStack;
int i;
char c;
StackInitiate(&myStack);
for(i=0;i<n;i++)
{
{
if((exp[i]=='(')||(exp[i]=='[')||(exp[i]=='{'))
StackPush(&myStack,exp[i]);
else if(exp[i]==')'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c=='(')
StackPop(&myStack,&c);
else if(exp[i]==')'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c!='(')
{
printf("左右括号配对次序不正确!\n");
return;
}
else if(exp[i]==']'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c=='[')
StackPop(&myStack,&c);
else if(exp[i]==']'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c!='[')
{
printf("左右括号配对次序不正确!\n");
return;
}
else if(exp[i]=='}'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c=='{')
StackPop(&myStack,&c);
else if(exp[i]=='}'&&StackNotEmpty(myStack)&&StackTop(myStack,&c)&&c!='{')
{
printf("左右括号配对次序不正确!\n");
return;
}
else if(((exp[i]==')')||(exp[i]==']')||(exp[i]'}'))&&!StackNotEmpty(myStack))
{
printf("右括号多于左括号!\n");
return;
}
}
if(StackNotEmpty(myStack))
printf("左括号多于右括号!\n");
else
printf("左右括号匹配正确!\n");
}
syntax error : missing ')' before 'constant'