EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134996066
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
Question
Book Icon
Chapter 19, Problem 14PC
Program Plan Intro

Balanced Parentheses

Program Plan:

  • Include required header files
  • Declare function prototype
  • Inside “main ()” function,
    • Declare a variable “strng”.
    • Get a string from the user.
    • Check if the Boolean function “is_Balanced ()” returns true.
      • If the condition is true then the string has balanced parentheses.
      •  If the condition is not true then the string does not have balanced parentheses.
  • In “is_Balanced ()” function,
    • Declare a Boolean variable “status”.
    • Create an object for stack.
    • Use for loop to step through each character in a string.
      • Use Switch…Case structure check the character has set of parentheses or not.
        • If left parenthesis is detected,
          • Push it into the stack using the function “push ()”.
        • If right parenthesis is detected,
          • Check if the stack is empty using the function “empty()”.
            • If the stack is empty then assign “false”
            • If the stack is not empty then assign “true”
    • Check if the stack is empty and assign “true”. Else, assign “false”.
    • Return the variable “status”.

Blurred answer
Students have asked these similar questions
A set of instructions may be used to show a function's return address. Remember that any modifications you make to the stack cannot prevent the procedure from returning to its caller.
Stacks 1-  Write a Python function that takes a user input of a word and returns True if it is a Palindrome and returns False otherwise (Your function should use a Stack data structure). A palindrome is a word that can be read the same backward as forward. Some examples of palindromic words are noon, civic, radar, level, rotor, kayak, reviver, racecar, redder, madam, and refer. 2-  Write a Python function that takes a stack of integer numbers and returns the maximum value of the numbers in the stack. The stack should have the same numbers before and after calling the function. 3-  Write a main function that tests the functions you wrote in 1 and 2 above and make sure that your code is well documented.
Stack using C++ programmijng language please  Write a program to input an arithmetic expression, then 1. Match nested brackets found the expression, if they are matched correctly proceed to step 2.2. Evaluate the expression. Please not that the operands of the expression may contain more than one digit. the cin of the arithmetic expression is :: ((5+(6/2*3)-2)+1)= you can use this function also :::  struct node { int data; node *next; node(int d,node *n=0) { data=d; next=n; } }; class stack { node *topp; public: stack(); void push(int el); bool pop(); int top(); bool top(int &el); //~stack(); //void operator=(stack &o); //stack(stack &o); }; stack::stack() { topp=0; } void stack::push(int el) { topp=new node(el,topp); } bool stack::pop() { if(topp==0) return false; node *t=topp; topp=topp->next; delete t; return true; } int stack::top() { if(topp!=0) return topp->data; } bool stack::top(int &el) { if(topp==0) return false; el=topp->data; return true; }
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning