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
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…
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.
5. 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.
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
- Could you please explain the Write Through method?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_forwardDetermine the stack's efficacy when allowed to be who it is.arrow_forward
- "please turn this python code to c++" class hashTable:def _init_(self):self.size = int(input('Enter the size of hash table:'))#initializwe the table with 0self.table = list(None for i in range(self.size))self.elementCount = 0# function to get the position for elementdef hashFunction(self,key):return key%self.size #function to check if hash table is full or notdef isFull(self):if self.elementCount == self.size:return Trueelse:return False#function to insert data into hash tabledef insert(self,data):#check if table is fullif self.isFull():print("hash table is full")return Falseposition = self.hashFunction(data)#checking if positiohn is emptyif self.table[position] == None:self.table[position] = dataself.elementCount+=1#if collision occur linear probing is doneelse:while self.table[position] != None:position+=1if position >= self.size:position = 0self.table[position] = data#function to display the hash tabledef display(self):for i in range( self.size):print(self.table[i]+"\n")ht =…arrow_forwardQ1: Write a java application for the stack operations with Linked List. Q2: Write java program to take the order from the customer and display the ordered items and total payment. If customer is entering the wrong name or not following the order to enter the menu it has to display error messages. (Find in the sample code) Sample Output:arrow_forwardInstructions: Implement a merge sort in Java, creating a class to hold the main method as well as the mergesort method (which should be a static method). The mergesort method should be able to use any Collection object and it should return a Collection that contains the contents of the original Collection, but in sorted order. The program must ask the user for the data to sort, using numeric data in this case, but your mergesort method must be capable of working with any Collection of Comparable objects. Use recursion.arrow_forward
- Python: Take your searching and sorting functions and put them into a class. The constructor should take a list as a parameter use the classes sort method and store the sorted list in a class property. A "search" method should return true or false if the item is found. A "count" method should return 0 or the number of times the item is found. For fun, you can create a method to generate a list of random numbers (and then sort it).arrow_forwardThis is Java project!arrow_forwardIn C++, first, make a set with 10 objects, then ask the user to enter a value for search in your list. if the value exists then print "the value you are looking for that is in the set", otherwise print "The value you are looking for that is not in the list".arrow_forward
- Project Description: In this project you implement an ArrayStack ADT and use the stack for implementing the following methods: a) Reverse an array of Words: Accept an array of words as input parameter and return an array of words in reverse order. Use the method signature: public static String[] reverseWords (String[] wordList) Example Input: Bird Cat Dog Elephant Output: Elephant Dog Cat Birdarrow_forwardPlease use C++, send screenshot of code running. Because this is the 2nd time I upload this photo, last answer I got, the code wasn’t compiled and run.arrow_forwardWhat is the best way to implement a stack or a queue so that it can hold an arbitrary number of elements? Select one: a. Using an array, and throwing an exception when the stack or queue is full. b. By creating a bigger array when the stack or queue is full, and copying the elements from the original array. c. Using linked lists to store the collection of elements.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