Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 20, Problem 20.14PE
Program Plan Intro
Postfix notation
Program plan:
- Import the required packages into the program.
- In the Exercise20_14 class,
- In the main() method,
- Check length of the argument. If yes, display the error message.
- Declare the variable.
- The for loop executes until the length of arguments. If yes, evaluate the expression.
- In try block, call evaluateExpression() method by passing the input expression.
- In catch, block, catch the exception.
- In the evaluateExpression() method.
- Create an object for Stack.
- Extract operands and operators.
- The while loop executes until token to scan the expression. If yes,
- Extract an expression.
- Check whether the length of expression is equal to 0. If yes, continue the code.
- Otherwise, check the expression. If yes, call processAnOperator() method.
- Otherwise, Call push() method to push an operand into stack.
- Return the result.
- In the processAnOperator() method.
- Check whether operator. If yes, perform the addition operation and push the result to stack.
- Otherwise, check whether operator. If yes, perform the subtraction operation and push the result to stack.
- Otherwise, check whether operator. If yes, perform the multiplication operation and push the result to stack.
- Otherwise, check whether operator. If yes, perform the division operation and push the result to stack.
- In the main() method,
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Identify the difference between STACK and ARRAY.
java please
C++
Chapter 20 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
Knowledge Booster
Similar questions
- (Please Help. My professor did not teach us any of this and will not answer my emails) Design a class named Queue for storing integers. Like a stack, a queue holds elements. In a stack, the elements are retreived in a last-in-first-out fashion. In a queue, the elements are retrieved in a first-in-first-out fashion. The class contains: An int[] data field named elements that stores the int values in the queue A data field named size that stores the number of elements in the queue A constructor that creates a Queue object with defult capacity 8 The method enqueue(int v) that adds v into the queue The method empty () that returns true if the queue is empty The method getSize() that returns the size of the queuearrow_forwardC++ PROGRAMMING (Linked list) complete the functions: You have to continue on implementing your Array List namely the following functions: Example ArrayList: [10, 30, 40, 50] void addAt(int num, int pos) This method will add the integer num to the posth position of the list. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the array will now look like this: [10, 20, 30, 40, 50] When the value of pos is greater than the size + 1 or less than one, output "Position value invalid" void removeAt(int pos) Removes the number in the posth position of the list. Performing removeAt(3) in the example list will remove the 3rd element of the list and the updated array will be: [10, 30, 50] When the value of pos is greater than the size or less than one, output "Position value invalid" My incomplete code: #include <cstdlib>#include <iostream>using namespace std; class ArrayList : public List { // : means "is-a" / extend int* array; int index;…arrow_forwardCode in C Program Write a stack and queue test driver. (more details in the pic below)arrow_forward
- 5. Evaluate the following postfix expression. (a + b) c - (d e) / f The postfix will be abcdef +-- / 3. b. ab + c de-f/ Write step by step procedure of solving this problem. Your Answer is (a or b) Use the above stack and fill (push) in operators, +, -, *, /, and '( '. Type "pop" beside the operators or '(' when you need to pop it out. Finally, convert the expression from infix to the postfix. Submitarrow_forwardWrite C++ code to convert a given infix expression to postfix expression. The steps and table below shows how infix to postfix conversion works in practice . 1. Search the Infix string from left to right. 2. Initialize a vacant stack. 3. If the scanned character is an operand add it to the Postfix string. 4. When the scanned character is an operator and if the stack is empty push the character to stack. 5. If a scanned character is an Operator and the stack is not empty, compare the precedence of the character with element on top of the stack. 6. When top Stack has higher precedence over the scanned character pop the stack else push the scanned character to stack. Repeat this procedure till the stack is not empty and top Stack has precedence over the character. 7. Reiterate 4 and 5 steps till all characters are scanned. 8. After all characters are scanned, we have to add any character that the stack may have to the Postfix string. 9. When stack is not empty add top Stack to Postfix…arrow_forwardExpression Conversion [Problem Description] Design a program which can tansfer an infix expression into a postfix expression and compute its result. Suppose the infix expression only includes’ *’, ‘/’, ‘+’, ‘-‘, ‘(‘, ‘)’ and the numbers are all integers. [Basic Requirements] You are required to use stack. The infix expression is inputted from keyboard as a string. If the input is legal, please convert the infix expression into postfix expression, calculate the result, and finally output the postfix expression and its value. If the infix expression entered is illegal, the program can prompt the user to input incorrectly and prompt the user to re-enter. please i need the program in c or c++ and please read the requirement below Algorithm design: The required data structure is designed, the algorithm idea and algorithm steps are given, and the time complexity of the algorithm is analyzed. Annotated source code: Paste the source code, preferably annotate the code.…arrow_forward
- Expression Conversion [Problem Description] Design a program which can tansfer an infix expression into a postfix expression and compute its result. Suppose the infix expression only includes’ *’, ‘/’, ‘+’, ‘-‘, ‘(‘, ‘)’ and the numbers are all integers. [Basic Requirements] You are required to use stack. The infix expression is inputted from keyboard as a string. If the input is legal, please convert the infix expression into postfix expression, calculate the result, and finally output the postfix expression and its value. If the infix expression entered is illegal, the program can prompt the user to input incorrectly and prompt the user to re-enter. If the input is do the code in c++ pleasearrow_forwardDo the whole program in C++ & Please kindly share the whole programarrow_forwardComplete my C++ program: Instructions: You have to continue on implementing your Array List namely the following functions: Example ArrayList: [10, 30, 40, 50] void addAt(int num, int pos) This method will add the integer num to the posth position of the list. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the array will now look like this: [10, 20, 30, 40, 50] When the value of pos is greater than the size + 1 or less than one, output "Position value invalid" void removeAt(int pos) Removes the number in the posth position of the list. Performing removeAt(3) in the example list will remove the 3rd element of the list and the updated array will be: [10, 30, 50] When the value of pos is greater than the size or less than one, output "Position value invalid" void removeAll(int num) Removes all instances of num in the array list. In this array [10, 10, 20, 30, 10], performing removeAll(10) will remove all 10's and the list will look like this: [20,…arrow_forward
- 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.arrow_forwardQ: Write the C++ code of Stack which is performed multiple task which are given below and performed all task by using Arrays. Push values 10, 20, 5 , 50, 40, 60, 45 Pop values 45, 60, and 40 Sort all values in Stack Please create is empty and stack function for telling them stack is empty or full.arrow_forwardProgramming Assignment # 3 Objective: To use stacks to solve a programming problem Write a Java program to evaluate infix expression (not necessarily fully parenthesized) using stacks. The priority of operators shall be taken into account. See https://en.wikipedia.org/wiki/Infix_notation for an example of an infix notation. Tip: You would probably need two stacks (a stack for numbers and stack for characters). Input: The program should ask the user to input the infix expression Output: The result of the calculation Assumptions: • You can use the Stack implementation of the Java API, or use one of the ones we have covered in class. • Assume that the input expressions contain only positive integer values, and that the output is always an integer. • The input that the user types can contain any string with the following characters: ( , ) , numbers operators, where numbers is any positive integer and operators are any of +, -, * , / • Your program assumes that the expression is…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning