I have Strings where I need to find brackets ()
, {}
, []
and using stack to check correctness and if there is a mistake to print the position of mistake . So i split them into char array and then want to check symbol by symbol and if its match my map execute my method of pushing/popping to/from the stack.
I imagine it like this:
ParentStack s = new ParentStack();
Map<Character, Method> map = new HashMap<Character, Method>();
map.put('(', s.push('('));
map.put(')', s.pop()); //then check if its opposite
So is there something like this? Or I have to use switches?