Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 20.11, Problem 20.11.2CP
Program Plan Intro
In the EvaluateExpression program, the problem can be solved with help of two stacks such as operandStack and operatorStack.
Phase 1:
Initially, the program starts the scanning the given expression from left to right to extract the operands, operators, and parentheses.
- If the extracted element is operands, then push those operands into operandStack stack.
- If the extracted element is operator such as “+” or “-”.
- Process each and every operator at top of stack and then push it into operatorStack stack.
- If the extracted element is operator such as “*” or “/”.
- Process “*” or “/” operator at top of stack and then push it into operatorStack stack.
- If the extracted element is symbol such as “(”.
- Process “(” symbol at top of stack and then push it into operatorStack stack.
- If the extracted element is symbol such as “)”.
- Process “)” symbol at top of stack and then push it into operatorStack stack. Repeatedly process the operators until “(” symbol.
Phase 2:
- Clear the stack from the top of operatorStack until empty the operatorStack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You are required to implement
expression evaluation. Take input an
expression and convert it into postfix
and then calculate the result using
stack.
00:08 !
4. Evaluate the following postfix expression.
3 55 * + 5 7 + 6/-
The value of the above postfix expression is
a
26
b.
22
Write step by step procedure of solving this problem.
Your Answer is
(a or b)
Use the above stack and fill (push)
in numbers. Type "pop" beside the
number when you need to pop it out.
Finally, find the postfix expression value.
Next
1. Use a below-given starter code. Use StackInterface.(h), and ArrayStack.(h,cpp). You will write your own StackDriver.cpp application file. IT'S IN C++Also...If the class that you create is Star, remember that you will declare your stack as follows:ArrayStack<Star> myStarStack;and you will push, pop, and peek Star objects.2. Create your own class definition. I should have at least one attribute, a constructor, and set and get methods for each attribute in your class.NOTE: If your class is offensive your lab will be rejected and you will receive a score of zero. I'm sorry I have to say this but there is a history of this happening and it is not appropriate.3. Write a driver program that exercises the Stack class from the downloaded starter code. Create multiple instances of your own class and demonstrate the stack operations: push, pop, and peek. ( you write your own class that you will put on the stack and you will write a driver that pushes, peeks, and pops your class items…
Chapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 4. Write a program to declare a stack of char data type and insert all the lowercase alphabets in it, and print them by popping them back out of the stack.arrow_forwardThis lab will exercise your understanding of some of the concepts covered in Chapter 18: stacks 1. Create a test program that uses the attached code in myStack.h to do the following: a. Write a program that takes as input an arithmetic expression that uses{}, () and [] as grouping symbols b. Output a message indicating whether the expression contains matching grouping symbols. For example, {25 + (3-6) * 8} and 7 + 8 * 2 have matching grouping symbols (no symbols indicate matching) 5 + {(13 + 7)/ 8 - 2 * 9 does not have matching grouping symbols Use only {}, () and [] as grouping symbols c. Print out (console) a proper message indicating whether the expression has matching or non-matchinggrouping symbols. The program may be named any name of our choice, must have a .cpp extention; variables may be any nameof your choice.arrow_forward5. Write a program to declare a stack of char data type and insert all the uppercase alphabets in it, and print them by popping them back out of the stack.arrow_forward
- Write this program in Java using a custom method. Implementation details You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists. Use an array of strings to store the 4 strings listed in the description. Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below: determine the fruits to display (step 3 below) and print them determine if there are 3 or 4 of the same image display the results update the customer balance as necessary prompt to play or quit continue loop if customer wants to play and there's money for another game. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an…arrow_forwardIn C#: Run the following console application. This program should produce the union of two sets, but has several errors. Use a variety of debugging techniques to locate and correct the errors. NOTE: A set is a collection of like elements that does not contain any duplicates. The union of two sets is the set that contains all the elements in both sets. Formally: A union B = {x : x Î A or x Î B}read: A union B is the set of all x such that x is in A or x is in B Example: A = {1,2,3,4,5} and B = {2,4,6,8}, then A union B = {1,2,3,4,5,6,8} (notice, no duplicates!) Debug the program. When you find an error, comment out the offending line, give an explanation of the error, write a corrected line, and include a screenshot of your program running with successful output. Submit the modified files and screenshots of any breakpoints you use. Program using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace…arrow_forwardHow well do variables work for handling data lists? What do you think is going on?arrow_forward
- Answer correctly this time else give u bad rating and downvote Using STL stacks, implement an application that does the following: Fill 20 elements into the stack Using an array, sort the elements within the stack using merge sort Place sorted items into the stack again (so your stack becomes sorted) and print the contentarrow_forwardof range. 3. Use the method swap that you wrote in Exercise 2 to write a method that reverses the order of the items in a list alist.arrow_forwardCreate an application that takes a phrase from the user and writes it with the characters of each word backwards. To reverse the letters in each phrase, use a stack.Print the infix statement after removing it from the array.arrow_forward
- Create an iterator that returns numbers, starting with 1, and each sequence will increase by one (returning 1,2,3,4,5 etc.):arrow_forwardGive the index of the pivot value after the whole list below has been partitioned using the median-of-3 value as the pivot value. [93, 49, 60, 65, 40, 74, 50, 69, 58, 97, 64] Notes: • Your answer should be a single valid, non-negative, literal Python int value. For example, 123 is a valid int literal. • This is not asking for the complete quicksort. • Hint: you don't have to get everything in the exactly the right place, just the pivot value. You can do a rough partition, ensuring each value is on the appropriate side of the pivot value. • You can pre-check your answer (to check it's a valid, non-negative, literal int). Answer: (penalty regime: 10, 20, ... %) Precheck Checkarrow_forwardMake a code that reads a statement entered by the user and produces it with the characters for each word in the opposite order. Each word's letters should be reversed using a stack.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education