## DataStructures Help

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

### DataStructures Help

I really need help with this program, i just dont really know how to start it, theres 2 programs and i just am not sure what it is i have to do in either program.

1) Write a program using a stack that will check an equation to make sure that parentheses “(), brackets “[]} and braces “{}” match and are nested correctly. The equation should be entered in an edit box and then be checked when a “Check Parentheses” button is clicked. If a miss match is found, display an error by calling MessageBox(“Error message”) and terminate. If there are too many left characters or right characters, display a MessageBox and terminate. You do not have to rewrite the stack definitions or functions; just reference them as written above or from what we defined in class.

2) Write a program using recursion that will check an equation to make sure that parentheses “(), brackets “[]} and braces “{}” match and are nested correctly. The equation should be entered in an edit box and then be checked when a “Check Parentheses” button is clicked. If a miss match is found, display an error by calling MessageBox(“Error message”) and terminate. If there are too many left characters or right characters, display a MessageBox and terminate. You do not have to rewrite the stack definitions or functions; just reference them as written above or from what we defined in class.
flip

You don't know how to start it? Do you know what is a stack and how you create loops? :)
You could be a bit more specific unless you are going to ask money for solving the problem. <- that was a bad joke

For starters, here is one hint: When parsing the equation, save all parentheses encountered into the stack or check if a matching parenthesis exists in the stack. This is more or less the whole algorithm for problem 1.

raimo

Posts: 372
Joined: Fri Sep 26, 2003 6:50 am
Location: Finland

well i know like what to do for the program, i know what to do in english, i just am having trouble interpreting it into code
flip

According the the assignment, writing the GUI should be no problem.

So first implement the GUI using a dummy function for parenthesis checking which just shows the input string in a MsgBox().

Then you can start to flesh out that function.
The algorithm is easy and very similar for both cases.

1. parse the string from left to right.
1.2 ignore non-left and non-right characters.
1.3 if you find a left characters, remeber it.
1.4 if you find a right character:
1.4.1 if it's not matching with the last one remembered you found an error and abort parsing.
14.2 if it's matching with the last one remembered, revert to the one rememberd before the last one remembered and continue.

Both cases will differ mostly in the way you remeber the last one and revert to the one remembered before:
1. will be using the stack data structure developed in class.
2. will be using recursion

Now have fun implementing...

jgbauman

Posts: 358
Joined: Sat Sep 27, 2003 9:00 am