Computers and Technology

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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:30, artursino
Me2540 week 5 assignment what do i want to know?
Answers: 1
image
Computers and Technology, 22.06.2019 21:30, Nathaliasmiles
The graph shows median weekly earnings for full-time workers according to education level. which can you not conclude?
Answers: 2
image
Computers and Technology, 23.06.2019 10:50, Leffew
The volume v and paper surface area a of a conical paper cup are given by where r is the radius of the base of the cone and h is the height of the cone. a. by eliminating h, obtain the expression for a as a function of r and v. b. create a user-de ned function that accepts r as the only argument and computes a for a given value of v. declare v to be global within the function. c. for v ! 10 in.3 , use the function with the fminbnd function to compute the value of r that minimizes the area a. what is the corresponding value of the height h? investigate the sensitivity of the solution by plotting v versus r. how much can r vary about its optimal value before the area increases 10 percent above its minimum value?
Answers: 1
image
Computers and Technology, 23.06.2019 16:30, azainababbas
20 points archie wants to use a reflector as he photographs a newlywed couple. what would he consider in his choice? a. shadow and sunny b. homemade and professional c. lamps and boards d. incident and reflected e. neutral density and enhancement
Answers: 3
Do you know the correct answer?
A common problem in parsing computer languages and compiler implementations is determining if an inp...

Questions in other subjects: