subject

A common problem in parsing computer languages and compiler implementations is determining if an input string is balanced. That is, a string can be considered balanced if for every opening element ( (, [, <, etc) there is a corresponding closing element ( ), ], >, etc).
Today, we’re interested in writing a method that will determine if a String is balanced. Write a method, isBalanced(String s) that returns true if every opening element is matched by a closing element of exactly the same type. Extra opening elements, or extra closing elements, result in an unbalanced string. For this problem, we are only interested in three sets of characters -- {, (, and [ (and their closing equivalents, }, ), and ]). Other characters, such as <, can be skipped. Extra characters (letters, numbers, other symbols) should all be skipped. Additionally, the ordering of each closing element must match the ordering of each opening element. This is illustrated by examples below.
The following examples illustrate the expected behaviour:
is Balanced ("{{mustache templates use double curly braces}}") should return true
is Balanced("{{but here we have our template wrong!}") should return false
is Balanced("{ ( ( some text ) ) }") should return true
is Balanced("{ ( ( some text ) } )") should return false (note that the ordering of the last two elements is wrong)
Write an implementation that uses one or more Stacks to solve this problem. As a client of the Stack class, you are not concerned with how it works directly, just that it does work.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:30
Aconstruction company is creating a powerpoint presentation describing how they calculate costs during each construction step. they plan to email this presentation to clients. the individual clients will be watching the presentation slide show on their own personal computers. what is the most important formatting step the company should take to make the text readable and pleasing to the eye?
Answers: 2
question
Computers and Technology, 23.06.2019 12:00
Using the list, you can select the number of photos that will appear on each slide. a. theme b. frame shape c. pictures in album d. picture layout
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Anetwork security application that prevents access between a private and trusted network and other untrusted networks
Answers: 1
question
Computers and Technology, 24.06.2019 04:30
What is the process in which the software development team compiles information to determine the final product
Answers: 1
You know the right answer?
A common problem in parsing computer languages and compiler implementations is determining if an inp...
Questions
question
Mathematics, 27.02.2021 09:50
question
Physics, 27.02.2021 09:50
question
Computers and Technology, 27.02.2021 09:50
question
Mathematics, 27.02.2021 09:50
Questions on the website: 13722361