Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help to solve Balancing parenthesis problem 2

Status
Not open for further replies.

bryan33

Technical User
Jul 18, 2001
2
0
0
AU
Hello anyone who can help me to figure out how to do a problem to run with JDK 1.2

The Questions:
Write a program that determines whether parenthetic symbol ( ), [ ], { }, and <> are nested correctly in a string of characters. Your program should read a string from the user and display whether the string is parenthetically correct i.e. balancing the parenthesis.

The program written must use a stack to determine whether the string is parenthetically correct. It can use standard Java stack class or write own. If there is more than one class in the written program, put all classes in the same source file.

If the string is correct, displat the first character position (left to right, starting from 0) at which the program finds an error. Keep reading until the users enter an empty string.

Example.
Enter a string: (xy) ( pq [q-y] )
OK

Enter a string: ( ( [ [ a ] ) ] )
Error at position 6 : Found ) expected ]

*******Thank you for helping******
 
While most of us here would be happy to steer you in the right direction or help you with a particular section of the code you are stuck with, I cannot condone giving you the answer to what is obviously a homework assignment.
The only way you will learn this stuff is by giving it a go and working through the details.

 
aargh, these are just the sort of questions I got sick of during my masters degree. I think this one must be on the world wide curriculum for computer science questions. You should surf the net for a textbook answer, there is bound to be one somewhere. Try looking for anything by Per Brinch Hansen - he loves this kind of stuff. Static Apnea - snorkelling in a swimming pool without the snorkel?
 
Think through it logically. The answer is really simple to implement using a Stack. I assume you are familiar with Stacks. So the question I have for you is when you come to you first parenthetic symbol what you going to do with it?

Wushutwist
 
Hi Brian,

This is quite simple actually. But like what Wushutwist said, if we gave you the entire program, we are not actually helping you.. so I suggest that you can begin coding yourself first. If you have any problems, you can post your questions.

It might take some time at the beginning to get used to using stack(it took me quite some time to get my stack working too for 1 of my assignments last year and that assignment is a lot worse compared to what you have been given.)

If you have problems starting your program or having trouble understanding how stack works, you can email to me and I will guide you along.

Best of luck,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top