int maxlen=10000;
int i=0;
int k=1;
Stack* stk=Stack_Create(maxlen);
while(i<len&&k)
{
if(str[i]=='('||str[i]=='['||'{'==str[i])
Stack_Push(stk, str[i]);
else if(str[i]==')')
{ if('('==Stack_Top( stk))
{ Stack_Pop(stk);
k=1;
}
else
k=0;
}
else if(str[i]==']')
{ if('['==Stack_Top( stk))
{ Stack_Pop(stk);
k=1;
}
else
k=0;
}
else if(str[i]=='}')
{ if('{'==Stack_Top( stk))
{ Stack_Pop(stk);
k=1;
}
else
k=0;
}
i++;
}
if(!Stack_IsEmpty(stk))
k=0;
if(k==1)
printf("YES");
else
printf("NO");
educoder数据结构栈第二关
最新推荐文章于 2022-10-09 16:10:54 发布