Time remaining:
Stacks : Character Matching

label Programming
account_circle Unassigned
schedule 0 Hours
account_balance_wallet $5

2 Stacks: Character Matching

Consider the following Java interface for stacks:

public interface Stack<T>{

public T pop(); // returns the top element

// and removes it from the stack

public T top(); // returns top element without removal

public void push(T item); // adds an item to the top

public 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 returns

true

if and only if

cand

is

balanced

in its characters. A string is balanced in

its characters if:

1.

it is empty

2.

it has the form

a xs a

where the

xs

consists of zero or more strings that are balanced

in their characters.

Thus, the following strings:

abbcdeedca

aa

112211

12233441

are all balanced in their characters.

matchTest

must

use a

Stack

to carry out its task

Nov 30th, -0001
it not possible
Jun 29th, 2013

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Nov 30th, -0001
...
Nov 30th, -0001
Jun 29th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer