数据结构算法题

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:06:32
8. There is an expression with three kinds of brackets () [] {}. For example ([(#+#)*(#+#)] {(…..)}). Maybe the format of the expression is incorrect such as [()[)…((, ({}(…), ([])(, {[{}})))), ]([([(.
(the brackets have been put with wrong positions)
Design an algorithm for checking the format of the expression with brackets.
If the format of the expression is correct then the function return true.
If the format of the expression is incorrect then the function return false.

这是道应用栈的算法题
1.定义一个栈
2.对表达式进行检测,当读到({[时进栈
3.当读到)}]时,拿读到的与栈顶元素比较,当配套时,栈顶元素出栈
当不配套时,return false
4.当表达式读完,栈中没有({[,return true,反之,当仍然存有时,
return false
具体程序,自己编一下,算法大概如此