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
In c++
How well do variables work for handling data lists? What do you think is going on?
#in c++
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
- Create an iterator that returns numbers, starting with 1, and each sequence will increase by one (returning 1,2,3,4,5 etc.):arrow_forwardNeed help with this in Java Implement a “To Do” list. Tasks have a priority between 1 and 9, and a description (which you can come up with on your own, say, “wash dishes”). The program is going to prompt the user to enter the tasks by running the method add_priority_description, the program adds a new task and prints the current list with priority 1 tasks on the top, and priority 9 tasks at the bottom. The program will continue to ask the user if they want to add another tasks, and repeat the add_priority_description method, or enters Q to run the quit method to quit the program. Sample output (not limited to) 1. Study for the final 1. Take the final 2. Watch Justice League with friends 3. Play ball 9. Wash Dishes 9. Clean room. There is a possibility of two tasks having the same priority. If so, the last task that was entered gets to be printed first. Use HEAP in your solution. (Java)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_forward
- Can you please write the follwing in Java. 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 ArrayList. You'll have to do…arrow_forwardIn C++arrow_forwardTask 2:Modify main() so that it asks the user for a second number to be searched for, and makethe text give an answer like in the example runs based on the return value fromcountElement() instead of counting. Example run: Example runs (user input in bold, comments not partof the output initalic):Number: 5Number: 7Number: 3Number: 9Number: 1Number: 10Number: 8Number: 1Number: 9Number: 7What to search for: 9And another number to search for: 1Both numbers occur in the arrayAnother example, same array as above: What to search for: 9And another number to search for: 13One of the numbers occurs in the arrayYet another example, same array as above:What to search for: 24And another number to search for: 13None of the numbers occur in the arrayarrow_forward
- Use C++ Programming language. The header file below defines a class for a simple hash table: hashMap.h Download hashMap.h Write a driver program to test the class with the following data: (520, "3100 Main St, Houston TX "); (37, "2200 Hayes Rd, Austin TX"); (226, "1775 West Airport St, San Antonio TX"); (273, "3322 Walnut Bend, Houston TX"); (491, "5778 Alabama, Waco TX"); (94, "3333 New St, Paris TX"); Make sure to test the find function for exiting and non-existing data 2. Modify the type of member key in class HashEntry from int to a string (this is useful is the key is e.g. the phone number or e-mail address). Use the string hash function discussed in class (see ppt notes) or search online for alternative functions that work on strings. 3. Modify the collision strategy of class HashMap to do separate chaining instead of linear probing. Be sure to modify the display function so that items in the bucket chains are also displayed in a pre-defined order…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_forwardThis problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints. You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator. 1 def only_evens (1st: list[list[int]]) -> list[list[int]]: """Return a list of the lists in 1st that contain only even integers. 4 >>> only_evens ([[1, 2, 4], [4, 0, 6], [22, 4, 3], [2]]) [[4, 0, 6], [2]] 6. 8. even_lists = [] 10 for sublist in 1st: 11 12 # write your code here (please read above for a suggested approach) 13 14 return even_listsarrow_forward
- This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints. You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator. 1 def only evens (1st: list[list[int]]) -> list[list[int]]: **"Return a list of the lists in 1st that contain only even integers. 2. 3. >>> only_evens ([[1, 2, 4], [4, e, 6], [22, 4, 3], [2]]) 4. [[4, e, 6], [2]] 8. even_lists = [] 10 for sublist in 1st: 11 12 13 14 return even_lists History Submit P Type here to search 100% 1:1 8°C Cloudy A 4) ENG 10/2arrow_forwardPlease help me with this question. I need to write this without using 'append' and 'list'. Write a program that reads in an integer n, reads n integer numbers from the user, and finally prints the sum of all even numbers, the average of all even numbers, the sum of all odd numbers, the average of all odd numbers, the sum of all the numbers, and the average of all numbers entered. Every negative integer number entry should be skipped and not used in any of the computations. Thank youarrow_forwardJAVA: Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in one of two lists: one list for short Strings that are 10 characters or fewer, and another list for long Strings that are 11 characters or more. After data entry is complete, prompt the user to enter which type of String list to display, either S for short or L for long and then output the correct list. For this exercise, you can assume that if the user does not request the list of short strings, the user wants the list of long strings. If a requested list has no Strings, output The list is empty. Prompt the user continuously until a sentinel value, ZZZ, is entered to quit the program. An example of the program is shown below: Enter a string or ZZZ to quit >> Green Enter a string or ZZZ to quit >> Green eggs Enter a string or ZZZ to quit >> Green eggs and ham Enter a string or ZZZ to quit >> I do not like green eggs and ham Enter…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