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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bracket matching using recursion

Status
Not open for further replies.

mdchesne

Programmer
Sep 11, 2005
3
US
console-based, non GUI

I need to match brackets ( [,{,and ('s ) in a string bordered by quotation marks. I tokenized the stream into a simgle string minus the quation marks and used a stack implemented by a linked list to check for matching brackets. Now I need to use recursion to do the same thing. the problem is, the input file has two lines:

"[abc(a) {bak} ]"
"jus{go(sd[sn] ) ah }"

the first line is to be checked by the stack, the second is to be checked by recursion. I have almost everything done for the stack part (minus the final test where i check if the stack is empty) but I have no clue how to test a second line using a totally different method!

All this code has to be in the same file called ParenthesisMatch.java which makes it even harded, IMO.

here's how it works:
[ [ ( ) ] ] would return "good"

[ [ ( ] ) ] would return "bad" because of nesting

[ [ ] would return "bad" because too many opening (same wiht closing)

here's my code if anyone has any idea how I can add recursion to do another line in the input file:
 
Sorry, posting by students doing their coursework is not allowed on this site -its for professionals only.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
alright, sorry. just trying to get osme help o i googled for "java forums, help" oh well, thanks for letting me know

would it help if i said it was for my boss? lol, nah, j/k, i'm gone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top