Programming
Stacks : Character Matching

Question Description

I need an explanation for this Programming question to help me study.

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

Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

it not possible

HMI 421 (16)
Boston College

Anonymous
Top quality work from this tutor! I’ll be back!

Anonymous
Heard about Studypool for a while and finally tried it. Glad I did caus this was really helpful.

Anonymous
Thank you! Reasonably priced given the quality

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4