用栈检查括号是否匹配,横线处应填入:
for (char& ch : s) {
if (ch=='('||ch=='{'||ch=='[') st.push(ch);
else {
if (st.empty()) return false;
________ // 在此处填入代码
if ((ch==')'&&top!='(')||(ch=='}'&&top!='{')||(ch==']'&&top!='[')) return false;
}
}
return st.empty();
- A. top = st.top(); st.pop();
- B. st.pop(); top = st.top();
- C. st.pop(); top = st.front();
- D. top = st.front(); st.pop();
正确答案:A