Stacks : Character Matching

2 Stacks: Character MatchingConsider the following Java interface for stacks:public interface Stack{public T pop(); // returns the top element// and removes it from the stackpublic T top(); // returns top element without removalpublic void push(T item); // adds an item to the toppublic boolean isEmpty(); // returns true if stack is empty}Write a non-recursive Java metho d with the signature:public static boolean matchTest(String cand);that returnstrueif and only ifcandisbalancedin its characters. A string is balanced inits characters if:1. it is empty2. it has the forma xs awhere thexsconsists of zero or more strings that are balancedin their characters.Thus, the following strings:abbcdeedcaaa11221112233441are all balanced in their characters.matchTestmustuse aStackto carry out its task

Looking for this or a Similar Assignment? Click below to Place your Order

Open chat