#pragma once
#include"stack.h"2. 栈的应用//用栈解决括号的匹配问题
int match(char a, char b)
{
if ((a =='( '&& b ==')') || (a =='['&&b ==']') || (a =='{'&&b =='}'))
return1;
elsereturn0;
}
int main()
{
Stackstack;
char c, e;
StackInit(&stack);
scanf("%c", &c);
while (c !='#')
{
if (StackEmpty(&stack))
StackPush(&stack, c);
else
{
e = StackTop(&stack);
if (!match(e, c))
StackPush(&stack, c);
else
StackPop(&stack, e);
}
scanf("%c", &c);
}
if (StackEmpty(&stack))
printf("The brackets are matched!\n");
else
printf("The brackets are not matched!\n");
system("pause");
}