Write a simple java program that takes input from the user as a fully parenthesized expression and converts it to a binary tree. Ex: (1+2 * (6-4)) or (A+B / (D-C))
When the tree is built, it should print the tree in some way.
import java.util.Stack; class Node { char value; Node left, right; Node(char item) { value = item; left = right = null; } } class ExpressionTree { boolean isOperator(char c) { if (c == '+' || c == '-' || c == '*' || c == '/' || c == '^') { return true; } return false; } void inorder(Node t) { if (t != null) { inorder(t.left); System.out.print(t.value + " "); inorder(t.right); } } Node constructTree(char postfix[]) { Stack<Node> st = new Stack(); Node t, t1, t2; for (int i = 0; i < postfix.length; i++) { if (!isOperator(postfix[i])) { t = new Node(postfix[i]); st.push(t); } else { t = new Node(postfix[i]); t1 = st.pop(); t2 = st.pop(); t.right = t1; t.left = t2; st.push(t); } } t = st.peek(); st.pop(); return t; } } public class Main { public static void main(String[] args) { ExpressionTree et = new ExpressionTree(); String postfix = "(1+2*(6-4))"; char[] charArray = postfix.toCharArray(); Node root = et.constructTree(charArray); System.out.println("infix expression is"); et.inorder(root); } }
Write a simple java program that takes input from the user as a fully parenthesized expression...
Write a program that takes as input a fully parenthesized , arithmetic expression and convert it to a binary expression tree. Your program should display the tree in some way and also print the value associated with the root. LANGUAGE In java Please answer...
(1) (50%) Write a C program that takes as input a fully parenthesized, arithmetic expression of binary operators +, -,*,/, and converts the expression into a binary expression tree. Your program should take input from the command line. The entire expression should be in a character string without any space in it An input string only includes floating numbers in the format of Y.YY, that is, one digit to the left of the decimal point and two digits to the...
**IN JAVA** Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string. i becomes ! a becomes @ m becomes M B becomes 8 o becomes . Ex: If the input is: mypassword the output is: [email protected]*s
Using Java write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word.
python! Input: For this first part you will be given a set of strings that represents a fully parenthesized infix expression that eventually (next assignment) be differentiated. The expression will be composed of single digit integers ("A"-"E"), the variable "X", parenthesis "(" and ")', and the binary operators +, -, *, /, and ^ (exponentiation). No spaces. Process: Generate a binary parse tree from the given input. Output: (1) Echo print the input string. (2) Print out the parse tree...
Question: Write a Java program for Evaluating Postfix Expression 1. Input a postfix expression from user. 2. Evaluate expression using double stack made of your own linked list. 3. Show the result of expression or error if incorrect. Evaluating Postfix Expression Input an expression: 2 10 + 9 6 - / Evaluating Postfix Expression Input an expression: 20 10 + 9 6 - 1 Evaluating Postfix Expression Input an expression: 2 10 + 9 - / Result = 4.0 Result...
. Write a program that takes integers from the user one at a time. Assume the input is some number of positive integers. The user will type in 0 to end the input and the 0 should not be counted as input. Your program should find how many times the user enters a multiple of 5 and then print it to the screen. If the input is 6 10 30 5 0, the output is 3 because 10, 30, and...
A Java Problem. E5.19 Write a program that takes user input describing a playing card in the following shorthand notation: А Ace 2... 10 Card values Jack Queen King Diamonds Hearts Spades Clubs Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades Implement a class Card whose constructor takes the card notation string and whose getDescription method returns a description of the card. If the notation string is not...
Write a C program that implements a simple shell. The shell takes a user command as input and execute the command. When a shell is started, it should take user command, execute it and display the output.
Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....