Public static boolean function

Assignment Help Basic Computer Science
Reference no: EM132493794

The brace checker class should have one public static boolean function: checkBraces, which takes a string parameter. The function should return true if the string parameter contains correctly nested parenthesis (), square-braces [], and curly-braces {}. Any letter other than those six should be ignored. Examples of correctly nested and incorrectly nested strings can be found in the tests for this class.

This is a task that would be quite dicult without a good algorithm (and a good stack) but is quite easy with a stack. Below is pseudocode for this algorithm:

1. begin by creating a stack. This stack will store characters to help us track which open-parenthesis (, left-square-brace [ and left-curly-brace { we've seen, but have not yet matched (an in what order).

2. Loop over each character in the string:

(a) if the character is an open parenthesis (, left-square-brace [ or left-curly-brace {simply push these characters onto the stack. This will remember that we've seen these characters.

(b) if the character is a closing-parenthesis ), right-square-brace ], or right-curly-brace} and the stack is empty, then return false, we've found a right brace/parenthesis which is not matched by a left brace/parenthesis.

(c) if the character is a closing-parenthesis ), right-square-brace ], or right-curly brace } and the top of the stack doesn't match it, then we've found a mismatched brace/parenthesis and can return false.

(d) Otherwise, if the character is a closing-parenthesis ), right-square-brace ], or right-curly-brace } and the top of the stack matches the letter, then we can pop the stack to mark that we've closed that brace/parenthesis, and continue

(e) If the letter is not one of the 6 braces/parenthesis letters, we can ignore it. 

3. Once we've processed every string, if the stack is empty, every left-parenthesis/brace was matched by a right-parenthesis/brace therefore we can return true.

4. If the stack is not empty, then there are some left-parenthesis/braces which were unmatched, and we should return false.

Reference no: EM132493794

Questions Cloud

What the reconciled cash balance as of october : What The reconciled cash balance as of October 31, 2019 is? The following information is available for Company Inc. for October 31, 2019
Identify the type of organizational assessment that you used : Each health care organization is unique in reference to its strengths and weaknesses. Assessing different aspects of the organization will assist in the.
Prepare horizontal and vertical analyse and with explanation : How to you make a horizontal analysis of the income statement data for Accra using 2008 as a base (show the amounts of increase or decrease)
What topic to perform research on should be accomplished : Identifying what topic to perform research on should be accomplished quickly because you will need sufficient time to perform your literature review.
Public static boolean function : The brace checker class should have one public static boolean function: checkBraces, which takes a string parameter. The function should return true
How you believe the requirements should change : How you believe these requirements should change. The facts that support your position, including how other countries have addressed these same issues.
What is the length of the instruction word : Considering only instructions that take 2 operands, what is the length of the instruction word?
Explaining your educational and career objective : You are student enrolling in college with no financial aid, but I am applying for a scholarship. For this assignment you are to write a one-page essay.
When should a company journalize a contingent? liability : According to? FASB, when should a company journalize a contingent? liability? Do not journalize the contingent liability under any circumstances.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd