• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

java help needed on parenthesis matching

mdchesne

Banned
I want to do some char matching using a stack and another by recursion. And the program will read any number of quoted string from standard-in and output to standard-out the results, good or bad, for each string. Someone recommended java tokenize the input stream, but i have no idea how to do that. I'm not really sure what or how I do this, other than when the program is given a string input, it will match certain chars (in this case, parenthesis, and will output good or bad.


--- basically: if there are the appropriate number of parentheses (closed and open), and prints good if the string has the corrent amount, and bad if too many closed or open or w/e. ---

ex:
input:
?ab(cde(fghijk)lm{nopq[r]stu}wxy)z?
?ab(cde(fghijk)lm{nopqrstu}wxyz?
?ab(cde(fghijk)lm{no(pq[r]stu}w)xy)z?

output:
Using stack:
good
bad
bad

Using recursion:
good
bad
bad

If someone can explain how to do this, much oblidged. I know very little java, so java-jargon doesn't help me much 😛
 
Originally posted by: JohnCU
Just pop and push using the stack.

/me waits for obligatory "wrong forum" comment.


Waited long enough.... Wrong forum...

C++. use cin.get()... it retrieves 1 character. Use 3 char stacks.
Left pars on one stack... Right Pars on another. Everything else on third.
Push them. Pop them. Compare. Done.
 
Originally posted by: DaveSimmons
Is this for a class? You'll get more homework help if you offer $10-20 per assignment.

lol, true dat. but because i am in college, i can't afford paying for help.

Originally posted by: JohnCU -and- vshash
Wrong Forum

meh, i debated over OT and Software, but figured this would me more OT. Yet... I bet this post will be buried under loads of "gas prices rising" by the end of this hour. lol. thanks for the help guys, I'll look into the stack pop and push.

But what baout this java tokenizer? I never used it before. how does it work?

But what about recursion? I need to do one with stacks and one with recursion.
 
I'm always tempted to give plausible but misleading information to people who post their Software questions in Off-Topic :evil:

Anyone else have this problem?
 
Originally posted by: DaveSimmons
I'm always tempted to give plausible but misleading information to people who post their Software questions in Off-Topic :evil:

Anyone else have this problem?

oh alright! jeeze, i'll move it.

MODS! DELETE THIS POST DO NOT MOVE I ALREADY POSTED A COPY ON SOFTWARE FORUMS

you guys are like a wife, nagging naggin naggin. lol. j/k
 
Originally posted by: mdchesne
Originally posted by: DaveSimmons
Is this for a class? You'll get more homework help if you offer $10-20 per assignment.

lol, true dat. but because i am in college, i can't afford paying for help.

Originally posted by: JohnCU -and- vshash
Wrong Forum

meh, i debated over OT and Software, but figured this would me more OT. Yet... I bet this post will be buried under loads of "gas prices rising" by the end of this hour. lol. thanks for the help guys, I'll look into the stack pop and push.

But what baout this java tokenizer? I never used it before. how does it work?

But what about recursion? I need to do one with stacks and one with recursion.

Java sux as a whole. C++ is more versatile and offers much better performance. who wants a language which has to be interpereted and run inside a java virtual processor, when you can have one which is compiled directly into binary and runs on its own.

About recursion...

process (string)
{
handle first character using cin.get().
(Left_par++ or Right_par++)

if string not empty...process(string minus first character)
else
compare (Left_par, Right_par)
}

edit: dammit I posed in a dead thread. too lazy to copy it to other thread.
 
Back
Top