I am trying to write a method in java to search a text file that I imported for specific characters. The file is actually a java program that I designed and converted to a .txt
file.
When an opening brace/bracket is found, I am supposed to add (push) it to a stack and then when a corresponding closing brace/bracket is found I am supposed to remove (pop) it from the stack.
The purpose is to see if I have the correct amount of )
, }
, ]
and >
to correspond with the (
, {
, [
and >
. If they all match up the method should return true, if they don't it should return false.
Anyone know how I can write this?
This is the sample implementation for balancing the brackets in a input text file