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 17:00
The two main ways in which marketers address the competition with their strategies are by satisfying a need better than a competition and by
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Annie is creating a corporate report for a company’s annual meeting. in the report, she wants to add the signature of various department heads. which device can annie use to capture signatures to include in the report? a. printer b. monitor c. e-reader d. digitizing tablet
Answers: 1
question
Computers and Technology, 23.06.2019 01:40
Writing a modular program in visual c++. i am new to this and not sure what i am missing. i am getting the following error: baddate.cpp: in function ‘int main()’: baddate.cpp: 50: 3: error: ‘else’ without a previous ‘if’elsehere are the instructions and code: writing a modular program in c++in this lab, you add the input and output statements to a partially completed c++ program. when completed, the user should be able to enter a year, a month, and a day. the program then determines if the date is valid. valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31.notice that variables have been declared for you.write the simulated housekeeping() function that contains the prompts and input statements to retrieve a year, a month, and a day from the user.include the output statements in the simulated endofjob() function. the format of the output is as follows: month/day/year is a valid date.ormonth/day/year is an invalid date.execute the program entering the following date: month = 5, day = 32, year = 2014. record the output of this program.execute the program entering the following date: month = 9, day = 21, year = 2002. record the output of this /* program name: baddate.cppfunction: this program determines if a date entered by the user is valid.input: interactiveoutput: valid date is printed or user is alerted that an invalid date was entered*/#include bool validatedate(int, int, int); using namespace std; int main(){// declare variablesint year; int month; int day; const int min_year = 0, min_month = 1, max_month = 12, min_day = 1, max_day = 31; bool validdate = true; // this is the work of the housekeeping() method// get the year, then the month, then the daycout< < "enter the year"< > year; cout< < "enter the month"< > month; cout< < "enter the day"< > day; // this is the work of the detailloop() method// check to be sure date is validif(year < = min_year) // invalid yearvaliddate = false; else if (month < min_month || month > max_month) // invalid monthvaliddate = false; else if (day < min_day || day > max_day) // invalid dayvaliddate = false; // this is the work of the endofjob() method// test to see if date is valid and output date and whether it is valid or notif(validdate == true); {// output statementcout<
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Which one of the following voltages should never be measured directly with a vom? a. 1200 v b. 500 v c. 800 v d. 100v
Answers: 2
You know the right answer?
A common problem in parsing computer languages and compiler implementations is determining if an inp...
Questions
question
Mathematics, 29.09.2019 13:30
question
Health, 29.09.2019 13:30
Questions on the website: 13722363