Home > categories > Hardware > Brackets > How can i make sure {(45+5)} brackets matches by using a stack?
Question:

How can i make sure {(45+5)} brackets matches by using a stack?

I had several solutions, but did work well.I'm only going to check whether brackets match or not by using stackI just need the explaination of that part

Answer:

If every left-bracket causes a push to the stack and every right-bracket causes a pop, the stack should never go negative and when the string is finished, the stack should be empty. If you're mixing different kinds of brackets, you should probably encode the entries and make sure a right-bracket does indeed close out the same type of left-bracket. Hope that helps.

Share to: