Implement a program that will use a stack structure to check for
correct placement of parentheses in an algebraic expression. Allow
the use of ( ) [ ] { } characters as grouping symbols. Make sure
that an error is reported for an expression of a form (...]. In
addition report other possible parentheses related errors (too many
levels, too many right paren., too many left paren.). Make sure to
use 'silent error reporting' (and report any possible errors
outside the main scanner loop).
Code:
import java.io.*;
import java.util.*;
import java.util.Stack;
public class CheckParentesis {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter string");
String str=sc.next();
String booleanCheck=CheckingParenthesis(str);
System.out.println("String "+booleanCheck);
}
public static String CheckingParenthesis(String expr)
{
if (expr.isEmpty())
return "Balanced";
Stack<Character> stack = new Stack<Character>();
for (int i = 0; i < expr.length(); i++)
{
char current = expr.charAt(i);
if (current == '{' || current == '(' || current == '[')
{
stack.push(current);
}
if (current == '}' || current == ')' || current == ']')
{
if (stack.isEmpty())
return "is having too many right parentheses";
char last = stack.peek();
if (current == '}' && last == '{' || current == ')'
&& last == '(' || current == ']' && last ==
'[')
stack.pop();
}
}
return stack.isEmpty()?" Balanced":"is having too many left
parentheses";
}
}
Output:



Implement a program that will use a stack structure to check for correct placement of parentheses...
JAVA - Without using build in functions Implement a program that will use a stack structure to check for correct placement of parentheses in an algebraic expression. Allow the use of ( ) [ ] { } characters as grouping symbols. Make sure that an error is reported for an expression of a form (...]. In addition report other possible parentheses related errors (too many levels, too many right paren., too many left paren.). Make sure to use 'silent error...
Assignment4: Evaluate Arithmetic Expressions. Requirements: Implement a concrete ArrayStack class that extends the IStack interface as we discussed in the class (any other different Stack class implementation, even if it is implemented by yourself, will not receive any credit). Write a test class called Evaluate and a method that evaluates an arithmatic expression, which is given by a string. import java.util.Scanner; public class Evaluate { public static void main(String[] args) } // your implementation // obtain user's input from keyboard...
C++: Learning Outcomes Implement two stacks and use them to implement an infix to prefix expression convertor Stacks A stack is an abstract data type which uses a sequential container and limits access to that container to one end. You may enter or remove from the container, but only at one end. Using the Linked List data structure from your last homework assignment, implement a Stack of type string. The Stack should only have one data member: the Linked List....
Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...
C++ Progrmaming Ch. 5 Stacks ** Please actually help! I have asked this question three times now and every response has not compiled and has many errors. *** Develop an expression manager that can do a balanced symbol check. Your program will read three different mathematical expressions from the user that are the followings: string expression = "{(0+1)*(2+3)}"; string expression = "{(0+1)+[4*(2+3)]}"; string expression = "{(0+1)+[4*(2+3)}}"; As you notice the expressions contain the following symbols: { , }, ( ,...
For this project you will implement a simple calculator. Your calculator is going to parse infix algebraic expressions, create the corresponding postfix expressions and then evaluate the postfix expressions. The operators it recognizes are: +, -, * and /. The operands are integers. Your program will either evaluate individual expressions or read from an input file that contains a sequence of infix expressions (one expression per line). When reading from an input file, the output will consist of two files:...
Please use the JAVA code attached as an input to the program
that must be created IN JAVA.
Instructions of the program:
java code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
import java.util.Random;
public class Rand_Z3_Exp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {...
Please use the JAVA code attached as an input to the program
that must be created IN JAVA.
Instructions of the program:
java code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
import java.util.Random;
public class Rand_Z3_Exp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {...
This project will allow you to write a program to get more practice with the stack and queue data structures, as well as more practice with object-oriented ideas that we explored in the previous projects. In this assignment you will be writing a simulation of an order-fulfillment system for a company like Amazon.com. These companies take orders for products and ship them to customers based on what they have in inventory. For this assignment you will be performing a scaled-back...
Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...