Question
Using Stack to solve problems in javascript 1) Design and Implement a Java program that reads a sentence from the user and prints the sentence
Using Stack to solve problems
in javascript
1) Design and Implement a Java program that reads a sentence from the user and prints the sentence with the characters of each word backwards. Use the ArrayStack in part 1 to reverse the characters of each word. A sample output is shown in Figure 1. Note that different sentence will be used for grading. It is required that the ArrayStack class should be utilized in solving this problem.
2) Implement a postfix-to-infix translator using stacks. Postfix notation1[1] is a notation for writing arithmetic expressions in which the operands appear before their operators. There are no precedence rules to learn, and parentheses are never needed. Because of this simplicity, some popular hand-held calculators use postfix notation to avoid the complications of the multiple parentheses required in nontrivial infix expressions. We have discussed how these postfix expressions can be evaluated using a stack in class. You are then to write a Java program to translate a postfix notation to infix notation. A sample output is shown in Figure 2, and some postfix expressions are given in as below for testing purpose. Note that different postfix notations will be used for grading. It is required that the LinkedStack class in part 1 should be utilized in solving this problem.
run: Enter a sentence: Hello nice to meet you in CS102 Reversing each word: ollet ecin ot teem uoy ni 2015C BUILD SUCCESSFUL (total time: 14 seconds) Figure 1: reverse character run: Enter a postfix expression: 3 4 + 2 * In Infix Notation: ((3 - 4) * 2) Translate another expression (Y/N]? Y Enter a postfix expression: 4 2 - 3 5 1 - * - In Infix Notation: ((4 + 2) + (3 (5 - 1))) Translate another expression (Y/N)? Figure 2: postfix-to-infix translator Some Postfix For Testing 45 72 +-*-16 - 3 4 + 2 * 7/2+ 5 7 + 6 2 - * 48 - 42 351-+* + 18 * 42 + 351 - * + 18 / run: Enter a sentence: Hello nice to meet you in CS102 Reversing each word: ollet ecin ot teem uoy ni 2015C BUILD SUCCESSFUL (total time: 14 seconds) Figure 1: reverse character run: Enter a postfix expression: 3 4 + 2 * In Infix Notation: ((3 - 4) * 2) Translate another expression (Y/N]? Y Enter a postfix expression: 4 2 - 3 5 1 - * - In Infix Notation: ((4 + 2) + (3 (5 - 1))) Translate another expression (Y/N)? Figure 2: postfix-to-infix translator Some Postfix For Testing 45 72 +-*-16 - 3 4 + 2 * 7/2+ 5 7 + 6 2 - * 48 - 42 351-+* + 18 * 42 + 351 - * + 18 /Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started